зеркало из https://github.com/mozilla/gecko-dev.git
Make anonymous classes really anonymous given self-identified global objects (326466, r=mrbkap).
This commit is contained in:
Родитель
44ffcbf617
Коммит
267d7d8156
226
js/src/jsapi.c
226
js/src/jsapi.c
|
@ -1225,52 +1225,18 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj)
|
|||
#define ATOM_OFFSET(name) offsetof(JSAtomState,name##Atom)
|
||||
#define CLASS_ATOM_OFFSET(name) offsetof(JSAtomState,classAtoms[JSProto_##name])
|
||||
#define OFFSET_TO_ATOM(rt,off) (*(JSAtom **)((char*)&(rt)->atomState + (off)))
|
||||
#define CLASP(name) (JSClass *)&js_##name##Class
|
||||
|
||||
/*
|
||||
* Table of class initializers and their atom offsets in rt->atomState.
|
||||
* If you add a "standard" class, remember to update this table.
|
||||
*/
|
||||
static struct {
|
||||
JSObjectOp init;
|
||||
size_t atomOffset;
|
||||
} standard_class_atoms[] = {
|
||||
{js_InitFunctionAndObjectClasses, CLASS_ATOM_OFFSET(Function)},
|
||||
{js_InitFunctionAndObjectClasses, CLASS_ATOM_OFFSET(Object)},
|
||||
{js_InitArrayClass, CLASS_ATOM_OFFSET(Array)},
|
||||
{js_InitBooleanClass, CLASS_ATOM_OFFSET(Boolean)},
|
||||
{js_InitDateClass, CLASS_ATOM_OFFSET(Date)},
|
||||
{js_InitMathClass, CLASS_ATOM_OFFSET(Math)},
|
||||
{js_InitNumberClass, CLASS_ATOM_OFFSET(Number)},
|
||||
{js_InitStringClass, CLASS_ATOM_OFFSET(String)},
|
||||
{js_InitCallClass, CLASS_ATOM_OFFSET(Call)},
|
||||
{js_InitExceptionClasses, CLASS_ATOM_OFFSET(Error)},
|
||||
{js_InitRegExpClass, CLASS_ATOM_OFFSET(RegExp)},
|
||||
#if JS_HAS_SCRIPT_OBJECT
|
||||
{js_InitScriptClass, CLASS_ATOM_OFFSET(Script)},
|
||||
#endif
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
{js_InitXMLClass, CLASS_ATOM_OFFSET(XML)},
|
||||
{js_InitNamespaceClass, CLASS_ATOM_OFFSET(Namespace)},
|
||||
{js_InitQNameClass, CLASS_ATOM_OFFSET(QName)},
|
||||
#endif
|
||||
#if JS_HAS_FILE_OBJECT
|
||||
{js_InitFileClass, CLASS_ATOM_OFFSET(File)},
|
||||
#endif
|
||||
#if JS_HAS_GENERATORS
|
||||
{js_InitIteratorClasses, CLASS_ATOM_OFFSET(StopIteration)},
|
||||
#endif
|
||||
{NULL, 0}
|
||||
};
|
||||
#define EAGER_ATOM(name) ATOM_OFFSET(name), NULL
|
||||
#define EAGER_CLASS_ATOM(name) CLASS_ATOM_OFFSET(name), NULL
|
||||
#define EAGER_ATOM_AND_CLASP(name) EAGER_CLASS_ATOM(name), CLASP(name)
|
||||
#define LAZY_ATOM(name) ATOM_OFFSET(lazy.name), js_##name##_str
|
||||
|
||||
/*
|
||||
* Table of top-level function and constant names and their init functions.
|
||||
* If you add a "standard" global function or property, remember to update
|
||||
* this table.
|
||||
*/
|
||||
typedef struct JSStdName {
|
||||
JSObjectOp init;
|
||||
size_t atomOffset; /* offset of atom pointer in JSAtomState */
|
||||
const char *name; /* null if atom is pre-pinned, else name */
|
||||
JSClass *clasp;
|
||||
} JSStdName;
|
||||
|
||||
static JSAtom *
|
||||
|
@ -1292,88 +1258,120 @@ StdNameToAtom(JSContext *cx, JSStdName *stdn)
|
|||
return atom;
|
||||
}
|
||||
|
||||
#define EAGERLY_PINNED_ATOM(name) ATOM_OFFSET(name), NULL
|
||||
#define EAGERLY_PINNED_CLASS_ATOM(name) CLASS_ATOM_OFFSET(name), NULL
|
||||
#define LAZILY_PINNED_ATOM(name) ATOM_OFFSET(lazy.name), js_##name##_str
|
||||
/*
|
||||
* Table of class initializers and their atom offsets in rt->atomState.
|
||||
* If you add a "standard" class, remember to update this table.
|
||||
*/
|
||||
static JSStdName standard_class_atoms[] = {
|
||||
{js_InitFunctionAndObjectClasses, EAGER_ATOM_AND_CLASP(Function)},
|
||||
{js_InitFunctionAndObjectClasses, EAGER_ATOM_AND_CLASP(Object)},
|
||||
{js_InitArrayClass, EAGER_ATOM_AND_CLASP(Array)},
|
||||
{js_InitBooleanClass, EAGER_ATOM_AND_CLASP(Boolean)},
|
||||
{js_InitDateClass, EAGER_ATOM_AND_CLASP(Date)},
|
||||
{js_InitMathClass, EAGER_ATOM_AND_CLASP(Math)},
|
||||
{js_InitNumberClass, EAGER_ATOM_AND_CLASP(Number)},
|
||||
{js_InitStringClass, EAGER_ATOM_AND_CLASP(String)},
|
||||
{js_InitCallClass, EAGER_ATOM_AND_CLASP(Call)},
|
||||
{js_InitExceptionClasses, EAGER_ATOM_AND_CLASP(Error)},
|
||||
{js_InitRegExpClass, EAGER_ATOM_AND_CLASP(RegExp)},
|
||||
#if JS_HAS_SCRIPT_OBJECT
|
||||
{js_InitScriptClass, EAGER_ATOM_AND_CLASP(Script)},
|
||||
#endif
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
{js_InitXMLClass, EAGER_ATOM_AND_CLASP(XML)},
|
||||
{js_InitNamespaceClass, EAGER_ATOM_AND_CLASP(Namespace)},
|
||||
{js_InitQNameClass, EAGER_ATOM_AND_CLASP(QName)},
|
||||
#endif
|
||||
#if JS_HAS_FILE_OBJECT
|
||||
{js_InitFileClass, EAGER_ATOM_AND_CLASP(File)},
|
||||
#endif
|
||||
#if JS_HAS_GENERATORS
|
||||
{js_InitIteratorClasses, EAGER_ATOM_AND_CLASP(StopIteration)},
|
||||
#endif
|
||||
{NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* Table of top-level function and constant names and their init functions.
|
||||
* If you add a "standard" global function or property, remember to update
|
||||
* this table.
|
||||
*/
|
||||
static JSStdName standard_class_names[] = {
|
||||
/* ECMA requires that eval be a direct property of the global object. */
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(eval)},
|
||||
{js_InitObjectClass, EAGER_ATOM(eval), NULL},
|
||||
|
||||
/* Global properties and functions defined by the Number class. */
|
||||
{js_InitNumberClass, LAZILY_PINNED_ATOM(NaN)},
|
||||
{js_InitNumberClass, LAZILY_PINNED_ATOM(Infinity)},
|
||||
{js_InitNumberClass, LAZILY_PINNED_ATOM(isNaN)},
|
||||
{js_InitNumberClass, LAZILY_PINNED_ATOM(isFinite)},
|
||||
{js_InitNumberClass, LAZILY_PINNED_ATOM(parseFloat)},
|
||||
{js_InitNumberClass, LAZILY_PINNED_ATOM(parseInt)},
|
||||
{js_InitNumberClass, LAZY_ATOM(NaN), NULL},
|
||||
{js_InitNumberClass, LAZY_ATOM(Infinity), NULL},
|
||||
{js_InitNumberClass, LAZY_ATOM(isNaN), NULL},
|
||||
{js_InitNumberClass, LAZY_ATOM(isFinite), NULL},
|
||||
{js_InitNumberClass, LAZY_ATOM(parseFloat), NULL},
|
||||
{js_InitNumberClass, LAZY_ATOM(parseInt), NULL},
|
||||
|
||||
/* String global functions. */
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(escape)},
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(unescape)},
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(decodeURI)},
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(encodeURI)},
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(decodeURIComponent)},
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(encodeURIComponent)},
|
||||
{js_InitStringClass, LAZY_ATOM(escape), NULL},
|
||||
{js_InitStringClass, LAZY_ATOM(unescape), NULL},
|
||||
{js_InitStringClass, LAZY_ATOM(decodeURI), NULL},
|
||||
{js_InitStringClass, LAZY_ATOM(encodeURI), NULL},
|
||||
{js_InitStringClass, LAZY_ATOM(decodeURIComponent), NULL},
|
||||
{js_InitStringClass, LAZY_ATOM(encodeURIComponent), NULL},
|
||||
#if JS_HAS_UNEVAL
|
||||
{js_InitStringClass, LAZILY_PINNED_ATOM(uneval)},
|
||||
{js_InitStringClass, LAZY_ATOM(uneval), NULL},
|
||||
#endif
|
||||
|
||||
/* Exception constructors. */
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(Error)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(InternalError)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(EvalError)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(RangeError)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(ReferenceError)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(SyntaxError)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(TypeError)},
|
||||
{js_InitExceptionClasses, EAGERLY_PINNED_CLASS_ATOM(URIError)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(Error), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(InternalError), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(EvalError), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(RangeError), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(ReferenceError), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(SyntaxError), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(TypeError), CLASP(Error)},
|
||||
{js_InitExceptionClasses, EAGER_CLASS_ATOM(URIError), CLASP(Error)},
|
||||
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
{js_InitAnyNameClass, EAGERLY_PINNED_CLASS_ATOM(AnyName)},
|
||||
{js_InitAttributeNameClass, EAGERLY_PINNED_CLASS_ATOM(AttributeName)},
|
||||
{js_InitXMLClass, LAZILY_PINNED_ATOM(XMLList)},
|
||||
{js_InitXMLClass, LAZILY_PINNED_ATOM(isXMLName)},
|
||||
{js_InitAnyNameClass, EAGER_ATOM_AND_CLASP(AnyName)},
|
||||
{js_InitAttributeNameClass, EAGER_ATOM_AND_CLASP(AttributeName)},
|
||||
{js_InitXMLClass, LAZY_ATOM(XMLList), &js_XMLClass},
|
||||
{js_InitXMLClass, LAZY_ATOM(isXMLName), NULL},
|
||||
#endif
|
||||
|
||||
#if JS_HAS_GENERATORS
|
||||
{js_InitIteratorClasses, EAGERLY_PINNED_CLASS_ATOM(Iterator)},
|
||||
{js_InitIteratorClasses, EAGER_ATOM_AND_CLASP(Iterator)},
|
||||
{js_InitIteratorClasses, EAGER_ATOM_AND_CLASP(Generator)},
|
||||
#endif
|
||||
|
||||
{NULL, 0, NULL}
|
||||
{NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static JSStdName object_prototype_names[] = {
|
||||
/* Object.prototype properties (global delegates to Object.prototype). */
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(proto)},
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(parent)},
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(count)},
|
||||
{js_InitObjectClass, EAGER_ATOM(proto), NULL},
|
||||
{js_InitObjectClass, EAGER_ATOM(parent), NULL},
|
||||
{js_InitObjectClass, EAGER_ATOM(count), NULL},
|
||||
#if JS_HAS_TOSOURCE
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(toSource)},
|
||||
{js_InitObjectClass, EAGER_ATOM(toSource), NULL},
|
||||
#endif
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(toString)},
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(toLocaleString)},
|
||||
{js_InitObjectClass, EAGERLY_PINNED_ATOM(valueOf)},
|
||||
{js_InitObjectClass, EAGER_ATOM(toString), NULL},
|
||||
{js_InitObjectClass, EAGER_ATOM(toLocaleString), NULL},
|
||||
{js_InitObjectClass, EAGER_ATOM(valueOf), NULL},
|
||||
#if JS_HAS_OBJ_WATCHPOINT
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(watch)},
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(unwatch)},
|
||||
{js_InitObjectClass, LAZY_ATOM(watch), NULL},
|
||||
{js_InitObjectClass, LAZY_ATOM(unwatch), NULL},
|
||||
#endif
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(hasOwnProperty)},
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(isPrototypeOf)},
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(propertyIsEnumerable)},
|
||||
{js_InitObjectClass, LAZY_ATOM(hasOwnProperty), NULL},
|
||||
{js_InitObjectClass, LAZY_ATOM(isPrototypeOf), NULL},
|
||||
{js_InitObjectClass, LAZY_ATOM(propertyIsEnumerable), NULL},
|
||||
#if JS_HAS_GETTER_SETTER
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(defineGetter)},
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(defineSetter)},
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(lookupGetter)},
|
||||
{js_InitObjectClass, LAZILY_PINNED_ATOM(lookupSetter)},
|
||||
{js_InitObjectClass, LAZY_ATOM(defineGetter), NULL},
|
||||
{js_InitObjectClass, LAZY_ATOM(defineSetter), NULL},
|
||||
{js_InitObjectClass, LAZY_ATOM(lookupGetter), NULL},
|
||||
{js_InitObjectClass, LAZY_ATOM(lookupSetter), NULL},
|
||||
#endif
|
||||
|
||||
{NULL, 0, NULL}
|
||||
{NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
#undef EAGERLY_PINNED_ATOM
|
||||
#undef LAZILY_PINNED_ATOM
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSBool *resolved)
|
||||
|
@ -1381,7 +1379,7 @@ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
|
|||
JSString *idstr;
|
||||
JSRuntime *rt;
|
||||
JSAtom *atom;
|
||||
JSObjectOp init;
|
||||
JSStdName *stdnm;
|
||||
uintN i;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
|
@ -1401,28 +1399,28 @@ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
|
|||
}
|
||||
|
||||
/* Try for class constructors/prototypes named by well-known atoms. */
|
||||
init = NULL;
|
||||
stdnm = NULL;
|
||||
for (i = 0; standard_class_atoms[i].init; i++) {
|
||||
atom = OFFSET_TO_ATOM(rt, standard_class_atoms[i].atomOffset);
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
init = standard_class_atoms[i].init;
|
||||
stdnm = &standard_class_atoms[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!init) {
|
||||
if (!stdnm) {
|
||||
/* Try less frequently used top-level functions and constants. */
|
||||
for (i = 0; standard_class_names[i].init; i++) {
|
||||
atom = StdNameToAtom(cx, &standard_class_names[i]);
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
init = standard_class_names[i].init;
|
||||
stdnm = &standard_class_names[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!init && !OBJ_GET_PROTO(cx, obj)) {
|
||||
if (!stdnm && !OBJ_GET_PROTO(cx, obj)) {
|
||||
/*
|
||||
* Try even less frequently used names delegated from the global
|
||||
* object to Object.prototype, but only if the Object class hasn't
|
||||
|
@ -1433,15 +1431,30 @@ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
|
|||
if (!atom)
|
||||
return JS_FALSE;
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
init = standard_class_names[i].init;
|
||||
stdnm = &standard_class_names[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (init) {
|
||||
if (!init(cx, obj))
|
||||
if (stdnm) {
|
||||
/*
|
||||
* If this standard class is anonymous and obj advertises itself as a
|
||||
* global object (in order to reserve slots for standard class object
|
||||
* pointers), then we don't want to resolve by name.
|
||||
*
|
||||
* If inversely, either id does not name a class, or id does not name
|
||||
* an anonymous class, or the global does not reserve slots for class
|
||||
* objects, then we must call the init hook here.
|
||||
*/
|
||||
if (stdnm->clasp &&
|
||||
(stdnm->clasp->flags & JSCLASS_IS_ANONYMOUS) &&
|
||||
(OBJ_GET_CLASS(cx, obj)->flags & JSCLASS_IS_GLOBAL)) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (!stdnm->init(cx, obj))
|
||||
return JS_FALSE;
|
||||
*resolved = JS_TRUE;
|
||||
}
|
||||
|
@ -1581,6 +1594,16 @@ JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
|
|||
return js_SetIdArrayLength(cx, ida, i);
|
||||
}
|
||||
|
||||
#undef ATOM_OFFSET
|
||||
#undef CLASS_ATOM_OFFSET
|
||||
#undef OFFSET_TO_ATOM
|
||||
#undef CLASP
|
||||
|
||||
#undef EAGER_ATOM
|
||||
#undef EAGER_CLASS_ATOM
|
||||
#undef EAGER_ATOM_CLASP
|
||||
#undef LAZY_ATOM
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
|
||||
JSObject **objp)
|
||||
|
@ -1589,9 +1612,6 @@ JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
|
|||
return js_GetClassObject(cx, obj, key, objp);
|
||||
}
|
||||
|
||||
#undef ATOM_OFFSET
|
||||
#undef OFFSET_TO_ATOM
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetScopeChain(JSContext *cx)
|
||||
{
|
||||
|
|
|
@ -473,7 +473,7 @@ msFromTime(jsdouble t)
|
|||
* Other Support routines and definitions
|
||||
*/
|
||||
|
||||
static JSClass date_class = {
|
||||
JSClass js_DateClass = {
|
||||
js_Date_str,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_Date),
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
|
@ -902,7 +902,7 @@ date_now(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|||
static jsdouble *
|
||||
date_getProlog(JSContext *cx, JSObject *obj, jsval *argv)
|
||||
{
|
||||
if (!JS_InstanceOf(cx, obj, &date_class, argv))
|
||||
if (!JS_InstanceOf(cx, obj, &js_DateClass, argv))
|
||||
return NULL;
|
||||
return JSVAL_TO_DOUBLE(OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE));
|
||||
}
|
||||
|
@ -1875,7 +1875,7 @@ date_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
bytes = JS_smprintf("(new %s(%s))", date_class.name, numStr);
|
||||
bytes = JS_smprintf("(new %s(%s))", js_Date_str, numStr);
|
||||
if (!bytes) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
|
@ -2119,7 +2119,7 @@ js_InitDateClass(JSContext *cx, JSObject *obj)
|
|||
|
||||
/* set static LocalTZA */
|
||||
LocalTZA = -(PRMJ_LocalGMTDifference() * msPerSecond);
|
||||
proto = JS_InitClass(cx, obj, NULL, &date_class, Date, MAXARGS,
|
||||
proto = JS_InitClass(cx, obj, NULL, &js_DateClass, Date, MAXARGS,
|
||||
NULL, date_methods, NULL, date_static_methods);
|
||||
if (!proto)
|
||||
return NULL;
|
||||
|
@ -2143,7 +2143,7 @@ js_NewDateObjectMsec(JSContext *cx, jsdouble msec_time)
|
|||
JSObject *obj;
|
||||
jsdouble *date;
|
||||
|
||||
obj = js_NewObject(cx, &date_class, NULL, NULL);
|
||||
obj = js_NewObject(cx, &js_DateClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSClass js_DateClass;
|
||||
|
||||
extern JSObject *
|
||||
js_InitDateClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
|
|
|
@ -66,14 +66,14 @@ static char js_filename_str[] = "fileName";
|
|||
static char js_lineno_str[] = "lineNumber";
|
||||
static char js_stack_str[] = "stack";
|
||||
|
||||
/* Forward declarations for ExceptionClass's initializer. */
|
||||
/* Forward declarations for js_ErrorClass's initializer. */
|
||||
static JSBool
|
||||
Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
||||
|
||||
static void
|
||||
exn_finalize(JSContext *cx, JSObject *obj);
|
||||
|
||||
static JSClass ExceptionClass = {
|
||||
JSClass js_ErrorClass = {
|
||||
js_Error_str,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_Error),
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
|
@ -245,7 +245,7 @@ js_ErrorFromException(JSContext *cx, jsval exn)
|
|||
if (JSVAL_IS_PRIMITIVE(exn))
|
||||
return NULL;
|
||||
obj = JSVAL_TO_OBJECT(exn);
|
||||
if (OBJ_GET_CLASS(cx, obj) != &ExceptionClass)
|
||||
if (OBJ_GET_CLASS(cx, obj) != &js_ErrorClass)
|
||||
return NULL;
|
||||
privateValue = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
if (JSVAL_IS_VOID(privateValue))
|
||||
|
@ -266,7 +266,7 @@ struct JSExnSpec {
|
|||
};
|
||||
|
||||
/*
|
||||
* All *Error constructors share the same JSClass, ExceptionClass. But each
|
||||
* All *Error constructors share the same JSClass, js_ErrorClass. But each
|
||||
* constructor function for an *Error class must have a distinct native 'call'
|
||||
* function pointer, in order for instanceof to work properly across multiple
|
||||
* standard class sets. See jsfun.c:fun_hasInstance.
|
||||
|
@ -552,7 +552,7 @@ Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|||
&pval);
|
||||
if (!ok)
|
||||
goto out;
|
||||
obj = js_NewObject(cx, &ExceptionClass, JSVAL_TO_OBJECT(pval), NULL);
|
||||
obj = js_NewObject(cx, &js_ErrorClass, JSVAL_TO_OBJECT(pval), NULL);
|
||||
if (!obj) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
|
@ -564,7 +564,7 @@ Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|||
* If it's a new object of class Exception, then null out the private
|
||||
* data so that the finalizer doesn't attempt to free it.
|
||||
*/
|
||||
if (OBJ_GET_CLASS(cx, obj) == &ExceptionClass)
|
||||
if (OBJ_GET_CLASS(cx, obj) == &js_ErrorClass)
|
||||
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, JSVAL_VOID);
|
||||
|
||||
/* Set the 'message' property. */
|
||||
|
@ -838,7 +838,7 @@ js_InitExceptionClasses(JSContext *cx, JSObject *obj)
|
|||
int protoIndex = exceptions[i].protoIndex;
|
||||
|
||||
/* Make the prototype for the current constructor name. */
|
||||
protos[i] = js_NewObject(cx, &ExceptionClass,
|
||||
protos[i] = js_NewObject(cx, &js_ErrorClass,
|
||||
(protoIndex != JSEXN_NONE)
|
||||
? protos[protoIndex]
|
||||
: obj_proto,
|
||||
|
@ -856,7 +856,7 @@ js_InitExceptionClasses(JSContext *cx, JSObject *obj)
|
|||
break;
|
||||
|
||||
/* Make this constructor make objects of class Exception. */
|
||||
fun->clasp = &ExceptionClass;
|
||||
fun->clasp = &js_ErrorClass;
|
||||
|
||||
/* Make the prototype and constructor links. */
|
||||
if (!js_SetClassPrototype(cx, fun->object, protos[i],
|
||||
|
@ -1003,7 +1003,7 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp)
|
|||
if (!ok)
|
||||
goto out;
|
||||
|
||||
errObject = js_NewObject(cx, &ExceptionClass, errProto, NULL);
|
||||
errObject = js_NewObject(cx, &js_ErrorClass, errProto, NULL);
|
||||
if (!errObject) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
|
@ -1111,7 +1111,7 @@ js_ReportUncaughtException(JSContext *cx)
|
|||
|
||||
if (!reportp &&
|
||||
exnObject &&
|
||||
OBJ_GET_CLASS(cx, exnObject) == &ExceptionClass) {
|
||||
OBJ_GET_CLASS(cx, exnObject) == &js_ErrorClass) {
|
||||
const char *filename;
|
||||
uint32 lineno;
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSClass js_ErrorClass;
|
||||
|
||||
/*
|
||||
* Initialize the exception constructor/prototype hierarchy.
|
||||
*/
|
||||
|
|
|
@ -902,7 +902,7 @@ call_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
|||
|
||||
JSClass js_CallClass = {
|
||||
js_Call_str,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE |
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE | JSCLASS_IS_ANONYMOUS |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Call),
|
||||
JS_PropertyStub, JS_PropertyStub,
|
||||
call_getProperty, call_setProperty,
|
||||
|
|
|
@ -572,7 +572,7 @@ generator_mark(JSContext *cx, JSObject *obj, void *arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static JSClass generator_class = {
|
||||
JSClass js_GeneratorClass = {
|
||||
js_Generator_str,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_IS_ANONYMOUS |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Generator),
|
||||
|
@ -590,7 +590,7 @@ js_NewGenerator(JSContext *cx, JSStackFrame *fp)
|
|||
JSGenerator *gen;
|
||||
jsval *newsp;
|
||||
|
||||
obj = js_NewObject(cx, &generator_class, NULL, NULL);
|
||||
obj = js_NewObject(cx, &js_GeneratorClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
|
@ -666,7 +666,7 @@ generator_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
JSBool ok;
|
||||
jsval junk;
|
||||
|
||||
if (!JS_InstanceOf(cx, obj, &generator_class, argv))
|
||||
if (!JS_InstanceOf(cx, obj, &js_GeneratorClass, argv))
|
||||
return JS_FALSE;
|
||||
|
||||
gen = (JSGenerator *)JS_GetPrivate(cx, obj);
|
||||
|
@ -723,7 +723,7 @@ js_InitIteratorClasses(JSContext *cx, JSObject *obj)
|
|||
return NULL;
|
||||
proto->slots[JSSLOT_ITER_STATE] = JSVAL_NULL;
|
||||
|
||||
if (!JS_InitClass(cx, obj, NULL, &generator_class, NULL, 0,
|
||||
if (!JS_InitClass(cx, obj, NULL, &js_GeneratorClass, NULL, 0,
|
||||
NULL, generator_methods, NULL, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@
|
|||
#define JSITER_COMPAT 0x2 /* compatibility flag for old XDR'd bytecode */
|
||||
#define JSITER_HIDDEN 0x4 /* internal iterator hidden from user view */
|
||||
|
||||
extern JSClass js_IteratorClass;
|
||||
|
||||
extern JSBool
|
||||
js_NewNativeIterator(JSContext *cx, JSObject *obj, uintN flags, jsval *vp);
|
||||
|
||||
|
@ -84,8 +82,6 @@ extern JSBool
|
|||
js_CallIteratorNext(JSContext *cx, JSObject *iterobj, uintN flags,
|
||||
jsid *idp, jsval *rval);
|
||||
|
||||
extern JSClass js_StopIterationClass;
|
||||
|
||||
#define VALUE_IS_STOP_ITERATION(cx,v) \
|
||||
(!JSVAL_IS_PRIMITIVE(v) && \
|
||||
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_StopIterationClass)
|
||||
|
@ -96,6 +92,10 @@ js_ThrowStopIteration(JSContext *cx, JSObject *obj);
|
|||
extern JSObject *
|
||||
js_NewGenerator(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JSClass js_GeneratorClass;
|
||||
extern JSClass js_IteratorClass;
|
||||
extern JSClass js_StopIterationClass;
|
||||
|
||||
extern JSObject *
|
||||
js_InitIteratorClasses(JSContext *cx, JSObject *obj);
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ static JSConstDoubleSpec math_constants[] = {
|
|||
{0,0,0,{0,0,0}}
|
||||
};
|
||||
|
||||
static JSClass math_class = {
|
||||
JSClass js_MathClass = {
|
||||
js_Math_str,
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Math),
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
|
@ -503,7 +503,7 @@ js_InitMathClass(JSContext *cx, JSObject *obj)
|
|||
{
|
||||
JSObject *Math;
|
||||
|
||||
Math = JS_DefineObject(cx, obj, js_Math_str, &math_class, NULL, 0);
|
||||
Math = JS_DefineObject(cx, obj, js_Math_str, &js_MathClass, NULL, 0);
|
||||
if (!Math)
|
||||
return NULL;
|
||||
if (!JS_DefineFunctions(cx, Math, math_static_methods))
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSClass js_MathClass;
|
||||
|
||||
extern JSObject *
|
||||
js_InitMathClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче