Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: test/cctest/test-modules.cc

Issue 2351113004: [modules] Expand API to allow linking and use it in d8 (Closed)
Patch Set: Use StrictEquals, remove check for bad instantiation behavior Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/flags.h"
6
7 #include "test/cctest/cctest.h"
8
9 using v8::Context;
10 using v8::HandleScope;
11 using v8::Isolate;
12 using v8::Local;
13 using v8::MaybeLocal;
14 using v8::Module;
15 using v8::ScriptCompiler;
16 using v8::ScriptOrigin;
17 using v8::String;
18 using v8::Value;
19
20 static MaybeLocal<Module> AlwaysEmptyResolveCallback(Local<Context> context,
21 Local<String> specifier,
22 Local<Module> referrer,
23 Local<Value> data) {
24 return MaybeLocal<Module>();
25 }
26
27 static int g_count = 0;
28 static MaybeLocal<Module> FailOnSecondCallResolveCallback(
29 Local<Context> context, Local<String> specifier, Local<Module> referrer,
30 Local<Value> data) {
31 if (g_count++ > 0) return MaybeLocal<Module>();
32 Local<String> source_text = v8_str("");
33 ScriptOrigin origin(v8_str("module.js"));
34 ScriptCompiler::Source source(source_text, origin);
35 return ScriptCompiler::CompileModule(CcTest::isolate(), &source)
36 .ToLocalChecked();
37 }
38
39 TEST(ModuleInstantiationFailures) {
40 Isolate* isolate = CcTest::isolate();
41 HandleScope scope(isolate);
42 LocalContext env;
43
44 Local<String> source_text = v8_str(
45 "import './foo.js';"
46 "export {} from './bar.js';");
47 ScriptOrigin origin(v8_str("file.js"));
48 ScriptCompiler::Source source(source_text, origin);
49 Local<Module> module =
50 ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
51 CHECK_EQ(2, module->GetModuleRequestsLength());
52 CHECK(v8_str("./foo.js")->StrictEquals(module->GetModuleRequest(0)));
53 CHECK(v8_str("./bar.js")->StrictEquals(module->GetModuleRequest(1)));
54
55 // Instantiation should fail.
56 CHECK(!module->Instantiate(env.local(), AlwaysEmptyResolveCallback));
57
58 // Start over again...
59 module = ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
60
61 // Instantiation should fail if a sub-module fails to resolve.
62 g_count = 0;
63 CHECK(!module->Instantiate(env.local(), FailOnSecondCallResolveCallback));
64 }
65
66 static MaybeLocal<Module> CompileSpecifierAsModuleResolveCallback(
67 Local<Context> context, Local<String> specifier, Local<Module> referrer,
68 Local<Value> data) {
69 ScriptOrigin origin(v8_str("module.js"));
70 ScriptCompiler::Source source(specifier, origin);
71 return ScriptCompiler::CompileModule(CcTest::isolate(), &source)
72 .ToLocalChecked();
73 }
74
75 TEST(ModuleEvaluation) {
76 Isolate* isolate = CcTest::isolate();
77 HandleScope scope(isolate);
78 LocalContext env;
79
80 Local<String> source_text = v8_str(
81 "import 'Object.expando = 5';"
82 "import 'Object.expando *= 2';");
83 ScriptOrigin origin(v8_str("file.js"));
84 ScriptCompiler::Source source(source_text, origin);
85 Local<Module> module =
86 ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
87 CHECK(module->Instantiate(env.local(),
88 CompileSpecifierAsModuleResolveCallback));
89 CHECK(!module->Evaluate(env.local()).IsEmpty());
90 ExpectInt32("Object.expando", 10);
91 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698