Remove lingering defaultValue calls with hint JSTYPE_OBJECT or JSTYPE_FUNCTION (554550, r=brendan).

This commit is contained in:
Andreas Gal 2010-04-11 20:55:22 -07:00
Родитель 2eb519b77f
Коммит ddceca133e
6 изменённых файлов: 26 добавлений и 159 удалений

Просмотреть файл

@ -2584,6 +2584,7 @@ JS_ResolveStub(JSContext *cx, JSObject *obj, jsval id)
JS_PUBLIC_API(JSBool)
JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
{
JS_ASSERT(type != JSTYPE_OBJECT && type != JSTYPE_FUNCTION);
return js_TryValueOf(cx, obj, type, vp);
}

Просмотреть файл

@ -1253,20 +1253,6 @@ call_resolve(JSContext *cx, JSObject *obj, jsval idval, uintN flags,
return JS_TRUE;
}
static JSBool
call_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
{
if (type == JSTYPE_FUNCTION) {
JSStackFrame *fp = (JSStackFrame *) obj->getPrivate();
if (fp) {
JS_ASSERT(fp->fun);
JS_ASSERT(fp->argv);
*vp = fp->calleeValue();
}
}
return JS_TRUE;
}
static uint32
call_reserveSlots(JSContext *cx, JSObject *obj)
{
@ -1284,7 +1270,7 @@ JS_FRIEND_DATA(JSClass) js_CallClass = {
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub,
call_enumerate, (JSResolveOp)call_resolve,
call_convert, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -1536,18 +1522,6 @@ fun_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
return JS_TRUE;
}
static JSBool
fun_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
{
switch (type) {
case JSTYPE_FUNCTION:
*vp = OBJECT_TO_JSVAL(obj);
return JS_TRUE;
default:
return js_TryValueOf(cx, obj, type, vp);
}
}
#if JS_HAS_XDR
/* XXX store parent and proto, if defined */
@ -1865,7 +1839,7 @@ JS_FRIEND_DATA(JSClass) js_FunctionClass = {
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, (JSResolveOp)fun_resolve,
fun_convert, fun_finalize,
JS_ConvertStub, fun_finalize,
NULL, NULL,
NULL, NULL,
js_XDRFunctionObject, fun_hasInstance,
@ -1885,24 +1859,11 @@ fun_toStringHelper(JSContext *cx, uint32_t indent, uintN argc, jsval *vp)
return JS_FALSE;
if (!VALUE_IS_FUNCTION(cx, fval)) {
/*
* If we don't have a function to start off with, try converting the
* object to a function. If that doesn't work, complain.
*/
if (!JSVAL_IS_PRIMITIVE(fval)) {
obj = JSVAL_TO_OBJECT(fval);
if (!obj->getClass()->convert(cx, obj, JSTYPE_FUNCTION, &fval)) {
return JS_FALSE;
}
vp[1] = fval;
}
if (!VALUE_IS_FUNCTION(cx, fval)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO,
js_Function_str, js_toString_str,
JS_GetTypeName(cx, JS_TypeOfValue(cx, fval)));
return JS_FALSE;
}
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO,
js_Function_str, js_toString_str,
JS_GetTypeName(cx, JS_TypeOfValue(cx, fval)));
return JS_FALSE;
}
obj = JSVAL_TO_OBJECT(fval);
@ -1948,7 +1909,7 @@ js_fun_call(JSContext *cx, uintN argc, jsval *vp)
LeaveTrace(cx);
obj = JS_THIS_OBJECT(cx, vp);
if (!obj || !obj->defaultValue(cx, JSTYPE_FUNCTION, &vp[1]))
if (!obj)
return JS_FALSE;
fval = vp[1];
@ -2016,7 +1977,7 @@ js_fun_apply(JSContext *cx, uintN argc, jsval *vp)
LeaveTrace(cx);
obj = JS_THIS_OBJECT(cx, vp);
if (!obj || !obj->defaultValue(cx, JSTYPE_FUNCTION, &vp[1]))
if (!obj)
return JS_FALSE;
fval = vp[1];
@ -2608,23 +2569,13 @@ JSFunction *
js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags)
{
jsval v;
JSObject *obj;
v = *vp;
obj = NULL;
if (JSVAL_IS_OBJECT(v)) {
obj = JSVAL_TO_OBJECT(v);
if (obj && obj->getClass() != &js_FunctionClass) {
if (!obj->defaultValue(cx, JSTYPE_FUNCTION, &v))
return NULL;
obj = VALUE_IS_FUNCTION(cx, v) ? JSVAL_TO_OBJECT(v) : NULL;
}
}
if (!obj) {
if (!VALUE_IS_FUNCTION(cx, v)) {
js_ReportIsNotFunction(cx, vp, flags);
return NULL;
}
return GET_FUNCTION_PRIVATE(cx, obj);
return GET_FUNCTION_PRIVATE(cx, JSVAL_TO_OBJECT(v));
}
JSObject *

Просмотреть файл

@ -206,15 +206,10 @@ Iterator(JSContext *cx, JSObject *iterobj, uintN argc, jsval *argv, jsval *rval)
flags = keyonly ? 0 : JSITER_FOREACH;
if (JS_IsConstructing(cx)) {
/* XXX work around old valueOf call hidden beneath js_ValueToObject */
if (!JSVAL_IS_PRIMITIVE(argv[0])) {
obj = JSVAL_TO_OBJECT(argv[0]);
} else {
obj = js_ValueToNonNullObject(cx, argv[0]);
if (!obj)
return JS_FALSE;
argv[0] = OBJECT_TO_JSVAL(obj);
}
obj = js_ValueToNonNullObject(cx, argv[0]);
if (!obj)
return false;
argv[0] = OBJECT_TO_JSVAL(obj);
return InitNativeIterator(cx, iterobj, obj, flags);
}
@ -363,15 +358,16 @@ js_ValueToIterator(JSContext *cx, uintN flags, jsval *vp)
AutoValueRooter tvr(cx);
/* XXX work around old valueOf call hidden beneath js_ValueToObject */
if (!JSVAL_IS_PRIMITIVE(*vp)) {
/* Common case. */
obj = JSVAL_TO_OBJECT(*vp);
} else {
/*
* Enumerating over null and undefined gives an empty enumerator.
* This is contrary to ECMA-262 9.9 ToObject, invoked from step 3 of
* the first production in 12.6.4 and step 4 of the second production,
* but it's "web JS" compatible.
* but it's "web JS" compatible. ES5 fixed for-in to match this de-facto
* standard.
*/
if ((flags & JSITER_ENUMERATE)) {
if (!js_ValueToObject(cx, *vp, &obj))

Просмотреть файл

@ -5310,6 +5310,8 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
jsval v, save;
JSString *str;
JS_ASSERT(hint != JSTYPE_OBJECT && hint != JSTYPE_FUNCTION);
v = save = OBJECT_TO_JSVAL(obj);
switch (hint) {
case JSTYPE_STRING:
@ -5373,15 +5375,9 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
if (!obj->getClass()->convert(cx, obj, hint, &v))
return JS_FALSE;
if (!JSVAL_IS_PRIMITIVE(v)) {
JSType type = JS_TypeOfValue(cx, v);
if (type == hint ||
(type == JSTYPE_FUNCTION && hint == JSTYPE_OBJECT)) {
goto out;
}
if (!js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0,
NULL, &v)) {
JS_ASSERT(hint != JS_TypeOfValue(cx, v));
if (!js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, NULL, &v))
return JS_FALSE;
}
}
break;
}
@ -5402,7 +5398,6 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
: JS_TYPE_STR(hint));
return JS_FALSE;
}
out:
*vp = v;
return JS_TRUE;
}
@ -6103,14 +6098,10 @@ js_ValueToObject(JSContext *cx, jsval v, JSObject **objp)
{
JSObject *obj;
if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
obj = NULL;
} else if (JSVAL_IS_OBJECT(v)) {
if (JSVAL_IS_OBJECT(v)) {
obj = JSVAL_TO_OBJECT(v);
if (!obj->defaultValue(cx, JSTYPE_OBJECT, &v))
return JS_FALSE;
if (!JSVAL_IS_PRIMITIVE(v))
obj = JSVAL_TO_OBJECT(v);
} else if (JSVAL_IS_VOID(v)) {
obj = NULL;
} else {
if (!js_PrimitiveToObject(cx, &v))
return JS_FALSE;

Просмотреть файл

@ -34,7 +34,6 @@ script regress-311792-01.js
script regress-311792-02.js
script regress-312278.js
script regress-313500.js
script regress-313630.js
script regress-313763.js
script regress-313803.js
script regress-313938.js

Просмотреть файл

@ -1,71 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Igor Bukanov
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var gTestfile = 'regress-313630.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 313630;
var summary = 'Root access in js_fun_toString';
var actual = '';
var expect = '';
printBugNumber(BUGNUMBER);
printStatus (summary);
var f = Function("return 1");
Function("return 2");
expect = f.toSource(0);
var likeFunction = {
valueOf: function() {
var tmp = f;
f = null;
return tmp;
},
__proto__: Function.prototype
};
var likeNumber = {
valueOf: function() {
gc();
return 0;
}
};
var actual = likeFunction.toSource(likeNumber);
printStatus(expect === actual);
reportCompare(expect, actual, summary);