Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: cherry-pick 39d546a from upstream v8 #20016

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 deps/v8/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Felix Geisendörfer <haimuiba@gmail.com>
Filipe David Manana <fdmanana@gmail.com>
Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Geoffrey Garside <ggarside@gmail.com>
Gus Caplan <me@gus.host>
Copy link
Member

Choose a reason for hiding this comment

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

Congrats on your first V8 commit. :-)

Gwang Yoon Hwang <ryumiel@company100.net>
Henrique Ferreiro <henrique.ferreiro@gmail.com>
Hirofumi Mako <mkhrfm@gmail.com>
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,11 @@ class V8_EXPORT Value : public Data {

bool IsWebAssemblyCompiledModule() const;

/**
* Returns true if the value is a Module Namespace Object.
*/
bool IsModuleNamespaceObject() const;

V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
Local<Context> context) const;
V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,10 @@ bool Value::IsSetIterator() const {

bool Value::IsPromise() const { return Utils::OpenHandle(this)->IsJSPromise(); }

bool Value::IsModuleNamespaceObject() const {
return Utils::OpenHandle(this)->IsJSModuleNamespace();
}

MaybeLocal<String> Value::ToString(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsString()) return ToApiHandle<String>(obj);
Expand Down
29 changes: 29 additions & 0 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27041,6 +27041,35 @@ TEST(ImportMeta) {
CHECK(result->StrictEquals(Local<v8::Value>::Cast(v8::Utils::ToLocal(meta))));
}

TEST(GetModuleNamespace) {
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);

Local<String> url = v8_str("www.google.com");
Local<String> source_text = v8_str("export default 5; export const a = 10;");
v8::ScriptOrigin origin(url, Local<v8::Integer>(), Local<v8::Integer>(),
Local<v8::Boolean>(), Local<v8::Integer>(),
Local<v8::Value>(), Local<v8::Boolean>(),
Local<v8::Boolean>(), True(isolate));
v8::ScriptCompiler::Source source(source_text, origin);
Local<Module> module =
v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
module->InstantiateModule(context.local(), UnexpectedModuleResolveCallback)
.ToChecked();
module->Evaluate(context.local()).ToLocalChecked();

Local<Value> ns_val = module->GetModuleNamespace();
CHECK(ns_val->IsModuleNamespaceObject());
Local<Object> ns = ns_val.As<Object>();
CHECK(ns->Get(context.local(), v8_str("default"))
.ToLocalChecked()
->StrictEquals(v8::Number::New(isolate, 5)));
CHECK(ns->Get(context.local(), v8_str("a"))
.ToLocalChecked()
->StrictEquals(v8::Number::New(isolate, 10)));
}

TEST(GlobalTemplateWithDoubleProperty) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
Expand Down
1 change: 1 addition & 0 deletions src/node_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace {
V(SharedArrayBuffer) \
V(Proxy) \
V(WebAssemblyCompiledModule) \
V(ModuleNamespaceObject) \


#define V(type) \
Expand Down
10 changes: 9 additions & 1 deletion test/parallel/test-util-types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --harmony-bigint
// Flags: --harmony-bigint --experimental-vm-modules
/* global SharedArrayBuffer */
'use strict';
const common = require('../common');
Expand Down Expand Up @@ -126,3 +126,11 @@ for (const [ value, _method ] of [
assert.deepStrictEqual(yup, expected[testedFunc]);
}
}

(async () => {
const m = new vm.Module('');
await m.link(() => 0);
m.instantiate();
await m.evaluate();
assert.ok(types.isModuleNamespaceObject(m.namespace));
})();