blob: db9f783d11e16efa5eb45d9c00155a6fa07f30aa [file] [log] [blame]
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/execution/arguments-inl.h"
#include "src/objects/js-function.h"
namespace v8 {
namespace internal {
RUNTIME_FUNCTION(Runtime_ShadowRealmWrappedFunctionCreate) {
DCHECK_EQ(2, args.length());
HandleScope scope(isolate);
Handle<NativeContext> native_context = args.at<NativeContext>(0);
Handle<JSReceiver> value = args.at<JSReceiver>(1);
RETURN_RESULT_OR_FAILURE(
isolate, JSWrappedFunction::Create(isolate, native_context, value));
}
// https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.importvalue
RUNTIME_FUNCTION(Runtime_ShadowRealmImportValue) {
DCHECK_EQ(1, args.length());
HandleScope scope(isolate);
Handle<String> specifier = args.at<String>(0);
Handle<JSPromise> inner_capability;
MaybeHandle<Object> import_options;
MaybeHandle<Script> referrer;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, inner_capability,
isolate->RunHostImportModuleDynamicallyCallback(referrer, specifier,
import_options));
// Check that the promise is created in the eval_context.
DCHECK_EQ(inner_capability->GetCreationContext().value(),
isolate->raw_native_context());
return *inner_capability;
}
RUNTIME_FUNCTION(Runtime_ShadowRealmThrow) {
DCHECK_EQ(2, args.length());
HandleScope scope(isolate);
int message_id_smi = args.smi_value_at(0);
Handle<Object> value = args.at(1);
MessageTemplate message_id = MessageTemplateFromInt(message_id_smi);
DirectHandle<String> string = Object::NoSideEffectsToString(isolate, value);
THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(message_id, string));
}
} // namespace internal
} // namespace v8