Issue #1570 - Implement globalThis

This resolves #1570
This commit is contained in:
wolfbeast 2020-05-30 21:14:43 +02:00 committed by Roy Tam
commit 5386cd812b
5 changed files with 44 additions and 3 deletions

View file

@ -1029,13 +1029,17 @@ JS_ResolveStandardClass(JSContext* cx, HandleObject obj, HandleId id, bool* reso
/* Check whether we're resolving 'undefined', and define it if so. */
JSAtom* idAtom = JSID_TO_ATOM(id);
JSAtom* undefinedAtom = cx->names().undefined;
if (idAtom == undefinedAtom) {
if (idAtom == cx->names().undefined) {
*resolved = true;
return DefineProperty(cx, global, id, UndefinedHandleValue, nullptr, nullptr,
JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_RESOLVING);
}
// Resolve a "globalThis" self-referential property if necessary.
if (idAtom == cx->names().globalThis) {
return GlobalObject::maybeResolveGlobalThis(cx, global, resolved);
}
/* Try for class constructors/prototypes named by well-known atoms. */
stdnm = LookupStdName(cx->names(), idAtom, standard_class_names);
@ -1088,6 +1092,7 @@ JS_MayResolveStandardClass(const JSAtomState& names, jsid id, JSObject* maybeObj
// better, we need a JSContext here; it's fine as it is.)
return atom == names.undefined ||
atom == names.globalThis ||
LookupStdName(names, atom, standard_class_names) ||
LookupStdName(names, atom, builtin_property_names);
}