Bug 702507 - rm JSCLASS_CONSTRUCT_PROTOTYPE and JS_IsConstructing_PossiblyWithGivenThisObjectAndPonies (r=waldo)

This commit is contained in:
Luke Wagner 2011-11-17 08:58:05 -08:00
parent 4f524913ba
commit f53924a3d9
2 changed files with 4 additions and 66 deletions

View File

@ -3129,9 +3129,7 @@ struct JSClass {
object in prototype chain
passed in via *objp in/out
parameter */
#define JSCLASS_CONSTRUCT_PROTOTYPE (1<<6) /* call constructor on class
prototype */
#define JSCLASS_DOCUMENT_OBSERVER (1<<7) /* DOM document observer */
#define JSCLASS_DOCUMENT_OBSERVER (1<<6) /* DOM document observer */
/*
* To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
@ -4975,50 +4973,6 @@ JS_IsConstructing(JSContext *cx, const jsval *vp)
return JSVAL_IS_MAGIC_IMPL(JSVAL_TO_IMPL(vp[1]));
}
/*
* In the case of a constructor called from JS_ConstructObject and
* JS_InitClass where the class has the JSCLASS_CONSTRUCT_PROTOTYPE flag set,
* the JS engine passes the constructor a non-standard 'this' object. In such
* cases, the following query provides the additional information of whether a
* special 'this' was supplied. E.g.:
*
* JSBool foo_native(JSContext *cx, uintN argc, jsval *vp) {
* JSObject *maybeThis;
* if (JS_IsConstructing_PossiblyWithGivenThisObject(cx, vp, &maybeThis)) {
* // native called as a constructor
* if (maybeThis)
* // native called as a constructor with maybeThis as 'this'
* } else {
* // native called as function, maybeThis is still uninitialized
* }
* }
*
* Note that embeddings do not need to use this query unless they use the
* aforementioned API/flags.
*/
static JS_ALWAYS_INLINE JSBool
JS_IsConstructing_PossiblyWithGivenThisObject(JSContext *cx, const jsval *vp,
JSObject **maybeThis)
{
jsval_layout l;
JSBool isCtor;
#ifdef DEBUG
JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
if (JS_ObjectIsFunction(cx, callee)) {
JSFunction *fun = JS_ValueToFunction(cx, JS_CALLEE(cx, vp));
JS_ASSERT((JS_GetFunctionFlags(fun) & JSFUN_CONSTRUCTOR) != 0);
} else {
JS_ASSERT(JS_GET_CLASS(cx, callee)->construct != NULL);
}
#endif
isCtor = JSVAL_IS_MAGIC_IMPL(JSVAL_TO_IMPL(vp[1]));
if (isCtor)
*maybeThis = MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(l);
return isCtor;
}
/*
* If a constructor does not have any static knowledge about the type of
* object to create, it can request that the JS engine create a default new

View File

@ -4317,7 +4317,7 @@ DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAt
* inference may need to access these, and js_GetClassPrototype will
* fail if it tries to do a reentrant reconstruction of the class.
*/
if (key != JSProto_Null && !(clasp->flags & JSCLASS_CONSTRUCT_PROTOTYPE)) {
if (key != JSProto_Null) {
if (!SetClassObject(cx, obj, key, fun, proto))
goto bad;
cached = true;
@ -4334,16 +4334,6 @@ DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAt
* XML support requires.
*/
ctor = fun;
if (clasp->flags & JSCLASS_CONSTRUCT_PROTOTYPE) {
Value rval;
if (!InvokeConstructorWithGivenThis(cx, proto, ObjectOrNullValue(ctor),
0, NULL, &rval)) {
goto bad;
}
if (rval.isObject() && &rval.toObject() != proto)
proto = &rval.toObject();
}
if (!LinkConstructorAndPrototype(cx, ctor, proto))
goto bad;
@ -4944,16 +4934,10 @@ js_ConstructObject(JSContext *cx, Class *clasp, JSObject *proto, JSObject *paren
/*
* If the instance's class differs from what was requested, throw a type
* error. If the given class has both the JSCLASS_HAS_PRIVATE and the
* JSCLASS_CONSTRUCT_PROTOTYPE flags, and the instance does not have its
* private data set at this point, then the constructor was replaced and
* we should throw a type error.
* error.
*/
obj = &rval.toObject();
if (obj->getClass() != clasp ||
(!(~clasp->flags & (JSCLASS_HAS_PRIVATE |
JSCLASS_CONSTRUCT_PROTOTYPE)) &&
!obj->getPrivate())) {
if (obj->getClass() != clasp) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_WRONG_CONSTRUCTOR, clasp->name);
return NULL;