summaryrefslogtreecommitdiff
path: root/js/src/vm
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-07-13 02:37:07 +0200
committerMartok <martok@martoks-place.de>2023-07-13 13:57:42 +0200
commit1eccb6f42ad7ee5ef887079d0a8a16e8f1ff9d50 (patch)
treed49e33f97e928502c7bb6e9ca069f254f0037b2e /js/src/vm
parent8e0e86face0bf8d19e7b23277078bf1e65779187 (diff)
downloaduxp-1eccb6f42ad7ee5ef887079d0a8a16e8f1ff9d50.tar.gz
Issue #2271 - Separate cloning of native and interpreted functions
Separate code paths make it easier to follow and specialize than a single one-size-fits-all function. Based-on: m-c 1405766, 1411954
Diffstat (limited to 'js/src/vm')
-rw-r--r--js/src/vm/Interpreter.cpp8
-rw-r--r--js/src/vm/SelfHosting.cpp40
2 files changed, 30 insertions, 18 deletions
diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp
index d7c1b8e84a..3515a9336b 100644
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -4302,7 +4302,13 @@ js::Lambda(JSContext* cx, HandleFunction fun, HandleObject parent)
{
MOZ_ASSERT(!fun->isArrow());
- RootedObject clone(cx, CloneFunctionObjectIfNotSingleton(cx, fun, parent));
+ JSFunction* clone;
+ if (fun->isNative()) {
+ MOZ_ASSERT(IsAsmJSModule(fun));
+ clone = CloneAsmJSModuleFunction(cx, fun);
+ } else {
+ clone = CloneFunctionObjectIfNotSingleton(cx, fun, parent);
+ }
if (!clone)
return nullptr;
diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp
index 357e151bde..c1276f5a43 100644
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -2909,23 +2909,29 @@ CloneObject(JSContext* cx, HandleNativeObject selfHostedObject)
RootedObject clone(cx);
if (selfHostedObject->is<JSFunction>()) {
RootedFunction selfHostedFunction(cx, &selfHostedObject->as<JSFunction>());
- bool hasName = selfHostedFunction->explicitName() != nullptr;
-
- // Arrow functions use the first extended slot for their lexical |this| value.
- MOZ_ASSERT(!selfHostedFunction->isArrow());
- js::gc::AllocKind kind = hasName
- ? gc::AllocKind::FUNCTION_EXTENDED
- : selfHostedFunction->getAllocKind();
- MOZ_ASSERT(!CanReuseScriptForClone(cx->compartment(), selfHostedFunction, cx->global()));
- Rooted<LexicalEnvironmentObject*> globalLexical(cx, &cx->global()->lexicalEnvironment());
- RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
- clone = CloneFunctionAndScript(cx, selfHostedFunction, globalLexical, emptyGlobalScope,
- kind);
- // To be able to re-lazify the cloned function, its name in the
- // self-hosting compartment has to be stored on the clone.
- if (clone && hasName) {
- clone->as<JSFunction>().setExtendedSlot(LAZY_FUNCTION_NAME_SLOT,
- StringValue(selfHostedFunction->explicitName()));
+ if (selfHostedFunction->isInterpreted()) {
+ bool hasName = selfHostedFunction->explicitName() != nullptr;
+
+ // Arrow functions use the first extended slot for their lexical |this| value.
+ MOZ_ASSERT(!selfHostedFunction->isArrow());
+ js::gc::AllocKind kind = hasName
+ ? gc::AllocKind::FUNCTION_EXTENDED
+ : selfHostedFunction->getAllocKind();
+
+ Handle<GlobalObject*> global = cx->global();
+ Rooted<LexicalEnvironmentObject*> globalLexical(cx, &global->lexicalEnvironment());
+ RootedScope emptyGlobalScope(cx, &global->emptyGlobalScope());
+ MOZ_ASSERT(!CanReuseScriptForClone(cx->compartment(), selfHostedFunction, global));
+ clone = CloneFunctionAndScript(cx, selfHostedFunction, globalLexical, emptyGlobalScope,
+ kind);
+ // To be able to re-lazify the cloned function, its name in the
+ // self-hosting compartment has to be stored on the clone.
+ if (clone && hasName) {
+ clone->as<JSFunction>().setExtendedSlot(LAZY_FUNCTION_NAME_SLOT,
+ StringValue(selfHostedFunction->explicitName()));
+ }
+ } else {
+ clone = CloneSelfHostingIntrinsic(cx, selfHostedFunction);
}
} else if (selfHostedObject->is<RegExpObject>()) {
RegExpObject& reobj = selfHostedObject->as<RegExpObject>();