Ignore:
Timestamp:
Feb 8, 2022, 12:42:04 PM (3 years ago)
Author:
[email protected]
Message:

[JSC] move function wrapping logic to a new Function type
https://bugs.webkit.org/show_bug.cgi?id=235382

Reviewed by Yusuke Suzuki.

JSTests:

Adds a new file testing CopyNameAndLength stuff in the ShadowRealm proposal,
and fix up assertions about this in shadow-realm-evaluate.js

  • stress/shadow-realm-evaluate.js:
  • stress/shadow-realm-remote-function-copy-length-and-name.js: Added.

Source/JavaScriptCore:

In this initial patch, there is still a lot of JS-builtin machinery,
including some duplicated functionality. Additionally, JIT support
has not been incorporated yet.

Broadly, the idea is that there are custom hooks for calling a
JSRemoteFunction, which perform the wrapping functionality. This avoids
the need for allocating closures which contain the wrapping logic.

TODO:

  • JIT/DFG/FTL support
  • structure caching (unnecessary since these are not constructors?)
  • improved baseline perf
  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • assembler/LinkBuffer.h:
  • builtins/BuiltinNames.h:
  • builtins/ShadowRealmPrototype.js:
  • bytecode/LinkTimeConstant.h:
  • dfg/DFGSpeculativeJIT.cpp:
  • ftl/FTLLowerDFGToB3.cpp:
  • heap/Heap.cpp:
  • heap/Heap.h:
  • inspector/JSInjectedScriptHost.cpp:
  • interpreter/Interpreter.cpp:
  • jit/AssemblyHelpers.h:
  • jit/JITOperations.cpp:
  • jit/JITOperations.h:
  • jit/ThunkGenerators.cpp:
  • jit/ThunkGenerators.h:
  • jsc.cpp:
  • runtime/ErrorInstance.cpp:
  • runtime/FunctionPrototype.cpp:
  • runtime/InternalFunction.cpp:
  • runtime/Intrinsic.cpp:
  • runtime/Intrinsic.h:
  • runtime/JSCast.h:
  • runtime/JSFunction.cpp:
  • runtime/JSFunction.h:
  • runtime/JSFunctionInlines.h:
  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:
  • runtime/JSRemoteFunction.cpp: Added.
  • runtime/JSRemoteFunction.h: Added.
  • runtime/VM.cpp:
  • runtime/VM.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r288442 r289417  
    5050#include "JSFinalizationRegistry.h"
    5151#include "JSFunction.h"
     52#include "JSFunctionInlines.h"
    5253#include "JSInternalPromise.h"
    5354#include "JSLock.h"
     
    367368static JSC_DECLARE_HOST_FUNCTION(functionDollarClearKeptObjects);
    368369static JSC_DECLARE_HOST_FUNCTION(functionDollarGlobalObjectFor);
     370static JSC_DECLARE_HOST_FUNCTION(functionDollarIsRemoteFunction);
    369371static JSC_DECLARE_HOST_FUNCTION(functionDollarAgentStart);
    370372static JSC_DECLARE_HOST_FUNCTION(functionDollarAgentReceiveBroadcast);
     
    650652        addFunction(vm, dollar, "clearKeptObjects", functionDollarClearKeptObjects, 0, static_cast<unsigned>(PropertyAttribute::None));
    651653        addFunction(vm, dollar, "globalObjectFor", functionDollarGlobalObjectFor, 1, static_cast<unsigned>(PropertyAttribute::None));
     654        addFunction(vm, dollar, "isRemoteFunction", functionDollarIsRemoteFunction, 1, static_cast<unsigned>(PropertyAttribute::None));
    652655       
    653656        dollar->putDirect(vm, Identifier::fromString(vm, "global"), globalThis());
     
    20832086
    20842087    return JSValue::encode(jsUndefined());
     2088}
     2089
     2090JSC_DEFINE_HOST_FUNCTION(functionDollarIsRemoteFunction, (JSGlobalObject* globalObject, CallFrame* callFrame))
     2091{
     2092    VM& vm = globalObject->vm();
     2093    auto scope = DECLARE_THROW_SCOPE(vm);
     2094
     2095    if (callFrame->argumentCount() < 1)
     2096        return JSValue::encode(throwException(globalObject, scope, createError(globalObject, "Not enough arguments"_s)));
     2097
     2098    JSValue arg = callFrame->argument(0);
     2099    return JSValue::encode(jsBoolean(isRemoteFunction(vm, arg)));
    20852100}
    20862101
Note: See TracChangeset for help on using the changeset viewer.