| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/flags.h" | 5 #include "src/flags.h" |
| 6 | 6 |
| 7 #include "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
| 8 | 8 |
| 9 namespace { |
| 10 |
| 9 using v8::Context; | 11 using v8::Context; |
| 10 using v8::HandleScope; | 12 using v8::HandleScope; |
| 11 using v8::Isolate; | 13 using v8::Isolate; |
| 12 using v8::Local; | 14 using v8::Local; |
| 13 using v8::MaybeLocal; | 15 using v8::MaybeLocal; |
| 14 using v8::Module; | 16 using v8::Module; |
| 15 using v8::ScriptCompiler; | 17 using v8::ScriptCompiler; |
| 16 using v8::ScriptOrigin; | 18 using v8::ScriptOrigin; |
| 17 using v8::String; | 19 using v8::String; |
| 18 using v8::Value; | 20 using v8::Value; |
| 19 | 21 |
| 20 static MaybeLocal<Module> AlwaysEmptyResolveCallback(Local<Context> context, | 22 MaybeLocal<Module> AlwaysEmptyResolveCallback(Local<Context> context, |
| 21 Local<String> specifier, | 23 Local<String> specifier, |
| 22 Local<Module> referrer, | 24 Local<Module> referrer, |
| 23 Local<Value> data) { | 25 Local<Value> data) { |
| 24 return MaybeLocal<Module>(); | 26 return MaybeLocal<Module>(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 static int g_count = 0; | 29 static int g_count = 0; |
| 28 static MaybeLocal<Module> FailOnSecondCallResolveCallback( | 30 MaybeLocal<Module> FailOnSecondCallResolveCallback(Local<Context> context, |
| 29 Local<Context> context, Local<String> specifier, Local<Module> referrer, | 31 Local<String> specifier, |
| 30 Local<Value> data) { | 32 Local<Module> referrer, |
| 33 Local<Value> data) { |
| 31 if (g_count++ > 0) return MaybeLocal<Module>(); | 34 if (g_count++ > 0) return MaybeLocal<Module>(); |
| 32 Local<String> source_text = v8_str(""); | 35 Local<String> source_text = v8_str(""); |
| 33 ScriptOrigin origin(v8_str("module.js")); | 36 ScriptOrigin origin(v8_str("module.js")); |
| 34 ScriptCompiler::Source source(source_text, origin); | 37 ScriptCompiler::Source source(source_text, origin); |
| 35 return ScriptCompiler::CompileModule(CcTest::isolate(), &source) | 38 return ScriptCompiler::CompileModule(CcTest::isolate(), &source) |
| 36 .ToLocalChecked(); | 39 .ToLocalChecked(); |
| 37 } | 40 } |
| 38 | 41 |
| 39 TEST(ModuleInstantiationFailures) { | 42 TEST(ModuleInstantiationFailures) { |
| 40 Isolate* isolate = CcTest::isolate(); | 43 Isolate* isolate = CcTest::isolate(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 "import 'Object.expando *= 2';"); | 85 "import 'Object.expando *= 2';"); |
| 83 ScriptOrigin origin(v8_str("file.js")); | 86 ScriptOrigin origin(v8_str("file.js")); |
| 84 ScriptCompiler::Source source(source_text, origin); | 87 ScriptCompiler::Source source(source_text, origin); |
| 85 Local<Module> module = | 88 Local<Module> module = |
| 86 ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked(); | 89 ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked(); |
| 87 CHECK(module->Instantiate(env.local(), | 90 CHECK(module->Instantiate(env.local(), |
| 88 CompileSpecifierAsModuleResolveCallback)); | 91 CompileSpecifierAsModuleResolveCallback)); |
| 89 CHECK(!module->Evaluate(env.local()).IsEmpty()); | 92 CHECK(!module->Evaluate(env.local()).IsEmpty()); |
| 90 ExpectInt32("Object.expando", 10); | 93 ExpectInt32("Object.expando", 10); |
| 91 } | 94 } |
| 95 |
| 96 TEST(EmbedderData) { |
| 97 Isolate* isolate = CcTest::isolate(); |
| 98 HandleScope scope(isolate); |
| 99 LocalContext env; |
| 100 |
| 101 Local<String> source_text = v8_str(""); |
| 102 ScriptOrigin origin(v8_str("file.js")); |
| 103 ScriptCompiler::Source source(source_text, origin); |
| 104 Local<Module> module = |
| 105 ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked(); |
| 106 CHECK(module->GetEmbedderData()->IsUndefined()); |
| 107 module->SetEmbedderData(v8_num(42)); |
| 108 CHECK_EQ(42, Local<v8::Int32>::Cast(module->GetEmbedderData())->Value()); |
| 109 } |
| 110 |
| 111 } // anonymous namespace |
| OLD | NEW |