Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/JavaScriptCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
runtime/JSPromiseConstructor.h
runtime/JSPropertyNameEnumerator.h
runtime/JSProxy.h
runtime/JSRemoteFunction.h
runtime/JSRunLoopTimer.h
runtime/JSScope.h
runtime/JSScriptFetchParameters.h
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ runtime/JSPromiseConstructor.cpp
runtime/JSPromisePrototype.cpp
runtime/JSPropertyNameEnumerator.cpp
runtime/JSProxy.cpp
runtime/JSRemoteFunction.cpp
runtime/JSRunLoopTimer.cpp
runtime/JSScope.cpp
runtime/JSScriptFetcher.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/builtins/BuiltinNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ namespace JSC {
macro(outOfLineReactionCounts) \
macro(emptyPropertyNameEnumerator) \
macro(sentinelString) \
macro(createRemoteFunction) \
macro(isRemoteFunction) \


namespace Symbols {
Expand Down
23 changes: 1 addition & 22 deletions Source/JavaScriptCore/builtins/ShadowRealmPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,7 @@ function wrap(fromShadowRealm, shadowRealm, target)
"use strict";

if (@isCallable(target)) {
var wrapped = function(/* args... */) {
var length = arguments.length;
var wrappedArgs = @newArrayWithSize(length);
for (var index = 0; index < length; ++index)
// Note that for arguments, we flip `fromShadowRealm` since to
// wrap a function from realm A to work in realm B, we need to
// wrap the arguments (from realm B) to work in realm A before
// calling the wrapped function
@putByValDirect(wrappedArgs, index, @wrap(!fromShadowRealm, shadowRealm, arguments[index]));

var result = target.@apply(@undefined, wrappedArgs);
return @wrap(fromShadowRealm, shadowRealm, result);
};
delete wrapped['name'];
delete wrapped['length'];

// Because this function (wrap) will run with the incubating realm
// active, we only need to fix the prototype on `wrapped` if we are
// moving the function from the incubating realm to the shadow realm
if (!fromShadowRealm)
@moveFunctionToRealm(wrapped, shadowRealm);
return wrapped;
target = @createRemoteFunction(target, fromShadowRealm ? null : shadowRealm);
} else if (@isObject(target)) {
@throwTypeError("value passing between realms must be callable or primitive");
}
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/bytecode/LinkTimeConstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class JSGlobalObject;
v(createPrivateSymbol, nullptr) \
v(emptyPropertyNameEnumerator, nullptr) \
v(sentinelString, nullptr) \
v(createRemoteFunction, nullptr) \
v(isRemoteFunction, nullptr) \
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use isRemoteFunction in tests



#define DECLARE_LINK_TIME_CONSTANT(name, code) name,
Expand Down
27 changes: 27 additions & 0 deletions Source/JavaScriptCore/jit/JITOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "JSGlobalObjectFunctions.h"
#include "JSInternalPromise.h"
#include "JSLexicalEnvironment.h"
#include "JSRemoteFunction.h"
#include "JSWithScope.h"
#include "LLIntEntrypoint.h"
#include "ObjectConstructor.h"
Expand Down Expand Up @@ -115,6 +116,32 @@ JSC_DEFINE_JIT_OPERATION(operationThrowStackOverflowErrorFromThunk, void, (JSGlo
ASSERT(vm.targetMachinePCForThrow);
}

JSC_DEFINE_JIT_OPERATION(operationGetWrappedValue, EncodedJSValue, (JSFunction* callee, EncodedJSValue encodedValue))
{
ASSERT(isRemoteFunction(callee));
JSGlobalObject* globalObject = callee->globalObject();
VM& vm = globalObject->vm();

CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);

JSGlobalObject* targetGlobalObject = jsCast<JSRemoteFunction*>(callee)->targetFunction()->globalObject();

JSValue value = JSValue::decode(encodedValue);
if (!value.isObject()) {
return encodedValue;
}

if (value.isCallable(vm)) {
JSFunction* targetCallee = static_cast<JSFunction*>(value.asCell());
return JSValue::encode(JSRemoteFunction::create(vm, targetGlobalObject, targetCallee));
}

auto scope = DECLARE_THROW_SCOPE(vm);
throwTypeError(targetGlobalObject, scope, "value passing between realms must be callable or primitive");
return encodedJSValue();
}

JSC_DEFINE_JIT_OPERATION(operationThrowIteratorResultIsNotObject, void, (JSGlobalObject* globalObject))
{
VM& vm = globalObject->vm();
Expand Down
Loading