зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1797750 - Part 6: Use an array to store extra handler values. r=mgaudet
This matches how we handle this case for Promise handlers and it's much faster. Depends on D160508 Differential Revision: https://phabricator.services.mozilla.com/D160509
This commit is contained in:
Родитель
d8ef6513e8
Коммит
28c89b7deb
|
@ -375,6 +375,14 @@ static bool ShadowRealm_evaluate(JSContext* cx, unsigned argc, Value* vp) {
|
||||||
args.rval());
|
args.rval());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ImportValueIndices : uint32_t {
|
||||||
|
CalleRealm = 0,
|
||||||
|
|
||||||
|
ExportNameString,
|
||||||
|
|
||||||
|
Length,
|
||||||
|
};
|
||||||
|
|
||||||
// MG:XXX: Cribbed/Overlapping with StartDynamicModuleImport; may need to
|
// MG:XXX: Cribbed/Overlapping with StartDynamicModuleImport; may need to
|
||||||
// refactor to share.
|
// refactor to share.
|
||||||
// https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
|
// https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
|
||||||
|
@ -491,27 +499,24 @@ static JSObject* ShadowRealmImportValue(JSContext* cx,
|
||||||
// [[ExportNameString]] », callerRealm).
|
// [[ExportNameString]] », callerRealm).
|
||||||
|
|
||||||
// The handler can only hold onto a single object, so we pack that into a new
|
// The handler can only hold onto a single object, so we pack that into a new
|
||||||
// JS Object, and store there.
|
// array, and store there.
|
||||||
Rooted<JSObject*> handlerObject(cx, NewPlainObject(cx));
|
Rooted<ArrayObject*> handlerObject(
|
||||||
|
cx,
|
||||||
|
NewDenseFullyAllocatedArray(cx, uint32_t(ImportValueIndices::Length)));
|
||||||
if (!handlerObject) {
|
if (!handlerObject) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rooted<Value> calleeRealmValue(cx, PrivateValue(callerRealm));
|
handlerObject->setDenseInitializedLength(
|
||||||
if (!JS_DefineProperty(cx, handlerObject, "calleeRealm", calleeRealmValue,
|
uint32_t(ImportValueIndices::Length));
|
||||||
JSPROP_READONLY)) {
|
handlerObject->initDenseElement(uint32_t(ImportValueIndices::CalleRealm),
|
||||||
return nullptr;
|
PrivateValue(callerRealm));
|
||||||
}
|
handlerObject->initDenseElement(
|
||||||
|
uint32_t(ImportValueIndices::ExportNameString), StringValue(exportName));
|
||||||
|
|
||||||
if (!JS_DefineProperty(cx, handlerObject, "exportNameString", exportName,
|
|
||||||
JSPROP_READONLY)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rooted<Value> handlerValue(cx, ObjectValue(*handlerObject));
|
|
||||||
Rooted<JSFunction*> onFulfilled(
|
Rooted<JSFunction*> onFulfilled(
|
||||||
cx,
|
cx,
|
||||||
NewHandlerWithExtraValue(
|
NewHandlerWithExtra(
|
||||||
cx,
|
cx,
|
||||||
[](JSContext* cx, unsigned argc, Value* vp) {
|
[](JSContext* cx, unsigned argc, Value* vp) {
|
||||||
// This is the export getter function from
|
// This is the export getter function from
|
||||||
|
@ -519,15 +524,14 @@ static JSObject* ShadowRealmImportValue(JSContext* cx,
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
MOZ_ASSERT(args.length() == 1);
|
MOZ_ASSERT(args.length() == 1);
|
||||||
|
|
||||||
Rooted<JSObject*> handlerObject(
|
auto* handlerObject = ExtraFromHandler<ArrayObject>(args);
|
||||||
cx, &ExtraValueFromHandler(args).toObject());
|
|
||||||
|
|
||||||
Rooted<Value> realmValue(cx);
|
Rooted<Value> realmValue(
|
||||||
Rooted<Value> exportNameValue(cx);
|
cx, handlerObject->getDenseElement(
|
||||||
MOZ_ALWAYS_TRUE(
|
uint32_t(ImportValueIndices::CalleRealm)));
|
||||||
JS_GetProperty(cx, handlerObject, "calleeRealm", &realmValue));
|
Rooted<Value> exportNameValue(
|
||||||
MOZ_ALWAYS_TRUE(JS_GetProperty(
|
cx, handlerObject->getDenseElement(
|
||||||
cx, handlerObject, "exportNameString", &exportNameValue));
|
uint32_t(ImportValueIndices::ExportNameString)));
|
||||||
|
|
||||||
// Step 1. Assert: exports is a module namespace exotic object.
|
// Step 1. Assert: exports is a module namespace exotic object.
|
||||||
Handle<Value> exportsValue = args[0];
|
Handle<Value> exportsValue = args[0];
|
||||||
|
@ -576,7 +580,7 @@ static JSObject* ShadowRealmImportValue(JSContext* cx,
|
||||||
// Step 9. Return ? GetWrappedValue(realm, value).
|
// Step 9. Return ? GetWrappedValue(realm, value).
|
||||||
return GetWrappedValue(cx, callerRealm, value, args.rval());
|
return GetWrappedValue(cx, callerRealm, value, args.rval());
|
||||||
},
|
},
|
||||||
promise, handlerValue));
|
promise, handlerObject));
|
||||||
if (!onFulfilled) {
|
if (!onFulfilled) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче