mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 933681 - Factor JSStdName table iteration into a helper function. r=jorendorff
This commit is contained in:
parent
a0af7450e0
commit
bba48b88fb
@ -1171,10 +1171,19 @@ typedef struct JSStdName {
|
||||
const Class *clasp;
|
||||
} JSStdName;
|
||||
|
||||
static Handle<PropertyName*>
|
||||
StdNameToPropertyName(JSContext *cx, const JSStdName *stdn)
|
||||
static const JSStdName*
|
||||
LookupStdName(JSRuntime *rt, HandleString name, const JSStdName *table)
|
||||
{
|
||||
return AtomStateOffsetToName(cx->runtime()->atomState, stdn->atomOffset);
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1304,9 +1313,7 @@ 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);
|
||||
@ -1321,59 +1328,34 @@ JS_ResolveStandardClass(JSContext *cx, HandleObject obj, HandleId id, bool *reso
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user