From f53924a3d9d7aa4f2777380ed72aff5a7df3e0f5 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 17 Nov 2011 08:58:05 -0800 Subject: [PATCH] Bug 702507 - rm JSCLASS_CONSTRUCT_PROTOTYPE and JS_IsConstructing_PossiblyWithGivenThisObjectAndPonies (r=waldo) --- js/src/jsapi.h | 48 +----------------------------------------------- js/src/jsobj.cpp | 22 +++------------------- 2 files changed, 4 insertions(+), 66 deletions(-) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index c86f6bc9224..14e2b071a3e 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -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 diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 14e26e1cf54..702480b67b8 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -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;