author | Bobby Holley <bobbyholley@gmail.com> |
Fri, 22 Nov 2013 10:55:42 -0800 | |
changeset 157160 | 30bbe45c775e205462b9dee6cfe4aae68591ec5f |
parent 157159 | b5ad39d10f98b3519e9e01dab3f8cb865c26c061 |
child 157161 | 72db5a6ae5c8c5e345eb51e51d93c7086e72c3e4 |
push id | 25703 |
push user | philringnalda@gmail.com |
push date | Sat, 23 Nov 2013 16:19:02 +0000 |
treeherder | mozilla-central@ad6589ed742c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | jorendorff |
bugs | 933681 |
milestone | 28.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
js/src/jsapi.cpp | file | annotate | diff | comparison | revisions |
--- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1166,20 +1166,29 @@ JS_InitStandardClasses(JSContext *cx, JS #define EAGER_ATOM_AND_OCLASP(name) EAGER_CLASS_ATOM(name), OCLASP(name) typedef struct JSStdName { ClassInitializerOp init; size_t atomOffset; /* offset of atom pointer in JSAtomState */ const Class *clasp; } JSStdName; -static Handle<PropertyName*> -StdNameToPropertyName(JSContext *cx, const JSStdName *stdn) -{ - return AtomStateOffsetToName(cx->runtime()->atomState, stdn->atomOffset); +static const JSStdName* +LookupStdName(JSRuntime *rt, HandleString name, const JSStdName *table) +{ + MOZ_ASSERT(name->isAtom()); + for (unsigned i = 0; table[i].init; i++) { + JS_ASSERT(table[i].clasp); + JSAtom *atom = AtomStateOffsetToName(rt->atomState, table[i].atomOffset); + MOZ_ASSERT(atom); + if (name == atom) + return &table[i]; + } + + return nullptr; } /* * Table of class initializers and their atom offsets in rt->atomState. * If you add a "standard" class, remember to update this table. */ static const JSStdName standard_class_atoms[] = { {js_InitFunctionClass, EAGER_CLASS_ATOM(Function), &JSFunction::class_}, @@ -1299,86 +1308,59 @@ static const JSStdName object_prototype_ #undef EAGER_CLASS_ATOM #undef EAGER_ATOM_CLASP #undef EAGER_ATOM_AND_CLASP JS_PUBLIC_API(bool) JS_ResolveStandardClass(JSContext *cx, HandleObject obj, HandleId id, bool *resolved) { JSRuntime *rt; - JSAtom *atom; const JSStdName *stdnm; - unsigned i; AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj, id); JS_ASSERT(obj->is<GlobalObject>()); *resolved = false; rt = cx->runtime(); if (!rt->hasContexts() || !JSID_IS_ATOM(id)) return true; RootedString idstr(cx, JSID_TO_STRING(id)); /* Check whether we're resolving 'undefined', and define it if so. */ - atom = rt->atomState.undefined; - if (idstr == atom) { + JSAtom *undefinedAtom = rt->atomState.undefined; + if (idstr == undefinedAtom) { *resolved = true; RootedValue undefinedValue(cx, UndefinedValue()); - return JSObject::defineProperty(cx, obj, atom->asPropertyName(), undefinedValue, + return JSObject::defineProperty(cx, obj, undefinedAtom->asPropertyName(), + undefinedValue, JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT | JSPROP_READONLY); } /* Try for class constructors/prototypes named by well-known atoms. */ - stdnm = nullptr; - for (i = 0; standard_class_atoms[i].init; i++) { - JS_ASSERT(standard_class_atoms[i].clasp); - atom = AtomStateOffsetToName(rt->atomState, standard_class_atoms[i].atomOffset); - if (idstr == atom) { - stdnm = &standard_class_atoms[i]; - break; - } - } - + stdnm = LookupStdName(rt, idstr, standard_class_atoms); + + /* Try less frequently used top-level functions and constants. */ + if (!stdnm) + stdnm = LookupStdName(rt, idstr, standard_class_names); + + /* + * Try even less frequently used names delegated from the global + * object to Object.prototype, but only if the Object class hasn't + * yet been initialized. + */ if (!stdnm) { - /* Try less frequently used top-level functions and constants. */ - for (i = 0; standard_class_names[i].init; i++) { - JS_ASSERT(standard_class_names[i].clasp); - atom = StdNameToPropertyName(cx, &standard_class_names[i]); - if (!atom) - return false; - if (idstr == atom) { - stdnm = &standard_class_names[i]; - break; - } - } - RootedObject proto(cx); if (!JSObject::getProto(cx, obj, &proto)) return false; - if (!stdnm && !proto) { - /* - * Try even less frequently used names delegated from the global - * object to Object.prototype, but only if the Object class hasn't - * yet been initialized. - */ - for (i = 0; object_prototype_names[i].init; i++) { - JS_ASSERT(object_prototype_names[i].clasp); - atom = StdNameToPropertyName(cx, &object_prototype_names[i]); - if (!atom) - return false; - if (idstr == atom) { - stdnm = &object_prototype_names[i]; - break; - } - } - } + if (!proto) + stdnm = LookupStdName(rt, idstr, object_prototype_names); } if (stdnm) { /* * If this standard class is anonymous, then we don't want to resolve * by name. */ if (stdnm->clasp->flags & JSCLASS_IS_ANONYMOUS)