Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
deps: cherry-pick 39d546a from upstream V8
Original commit message:

    [api] introduce v8::Value::IsModuleNamespaceObject

    This allows an embedder to check if a Value is a module namespace object.

    Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
    Change-Id: Idffceff451dd5f5c6a53d4cb3ce02c1c2c5b653c
    Reviewed-on: https://chromium-review.googlesource.com/1011762
    Reviewed-by: Georg Neis <neis@chromium.org>
    Commit-Queue: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#52597}

Refs: v8/v8@39d546a
  • Loading branch information
devsnek committed Apr 15, 2018
commit f8776d2632076c4ac871ea731d906d6d3848774c
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
Copy Markdown
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