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

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

Issue 934323004: Teach ModuleDescriptor about basic local exports (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Handled review comments, added message tests Created 5 years, 10 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 DCHECK(s != script_scope); 3239 DCHECK(s != script_scope);
3240 const i::AstRawString* name_x = avf.GetOneByteString("x"); 3240 const i::AstRawString* name_x = avf.GetOneByteString("x");
3241 3241
3242 // Get result from f's function context (that is g's outer context) 3242 // Get result from f's function context (that is g's outer context)
3243 i::Variable* var_x = s->Lookup(name_x); 3243 i::Variable* var_x = s->Lookup(name_x);
3244 CHECK(var_x != NULL); 3244 CHECK(var_x != NULL);
3245 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); 3245 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned);
3246 } 3246 }
3247 3247
3248 3248
3249 TEST(ExportsMaybeAssigned) {
3250 i::FLAG_use_strict = true;
3251 i::FLAG_harmony_scoping = true;
3252 i::FLAG_harmony_modules = true;
3253
3254 i::Isolate* isolate = CcTest::i_isolate();
3255 i::Factory* factory = isolate->factory();
3256 i::HandleScope scope(isolate);
3257 LocalContext env;
3258
3259 const char* src =
3260 "module A {"
3261 " export var x = 1;"
3262 " export function f() { return x };"
3263 " export const y = 2;"
3264 " module B {}"
3265 " export module C {}"
3266 "};"
3267 "A.f";
3268
3269 i::ScopedVector<char> program(Utf8LengthHelper(src) + 1);
3270 i::SNPrintF(program, "%s", src);
3271 i::Handle<i::String> source = factory->InternalizeUtf8String(program.start());
3272 source->PrintOn(stdout);
3273 printf("\n");
3274 i::Zone zone;
3275 v8::Local<v8::Value> v = CompileRun(src);
3276 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
3277 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3278 i::Context* context = f->context();
3279 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
3280 avf.Internalize(isolate);
3281
3282 i::Scope* script_scope =
3283 new (&zone) i::Scope(&zone, NULL, i::SCRIPT_SCOPE, &avf);
3284 script_scope->Initialize();
3285 i::Scope* s =
3286 i::Scope::DeserializeScopeChain(isolate, &zone, context, script_scope);
3287 DCHECK(s != script_scope);
3288 const i::AstRawString* name_x = avf.GetOneByteString("x");
3289 const i::AstRawString* name_f = avf.GetOneByteString("f");
3290 const i::AstRawString* name_y = avf.GetOneByteString("y");
3291 const i::AstRawString* name_B = avf.GetOneByteString("B");
3292 const i::AstRawString* name_C = avf.GetOneByteString("C");
3293
3294 // Get result from h's function context (that is f's context)
3295 i::Variable* var_x = s->Lookup(name_x);
3296 CHECK(var_x != NULL);
3297 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned);
3298 i::Variable* var_f = s->Lookup(name_f);
3299 CHECK(var_f != NULL);
3300 CHECK(var_f->maybe_assigned() == i::kMaybeAssigned);
3301 i::Variable* var_y = s->Lookup(name_y);
3302 CHECK(var_y != NULL);
3303 CHECK(var_y->maybe_assigned() == i::kNotAssigned);
3304 i::Variable* var_B = s->Lookup(name_B);
3305 CHECK(var_B != NULL);
3306 CHECK(var_B->maybe_assigned() == i::kNotAssigned);
3307 i::Variable* var_C = s->Lookup(name_C);
3308 CHECK(var_C != NULL);
3309 CHECK(var_C->maybe_assigned() == i::kNotAssigned);
3310 }
3311
3312
3313 TEST(InnerAssignment) { 3249 TEST(InnerAssignment) {
3314 i::Isolate* isolate = CcTest::i_isolate(); 3250 i::Isolate* isolate = CcTest::i_isolate();
3315 i::Factory* factory = isolate->factory(); 3251 i::Factory* factory = isolate->factory();
3316 i::HandleScope scope(isolate); 3252 i::HandleScope scope(isolate);
3317 LocalContext env; 3253 LocalContext env;
3318 3254
3319 const char* prefix = "function f() {"; 3255 const char* prefix = "function f() {";
3320 const char* midfix = " function g() {"; 3256 const char* midfix = " function g() {";
3321 const char* suffix = "}}"; 3257 const char* suffix = "}}";
3322 struct { const char* source; bool assigned; bool strict; } outers[] = { 3258 struct { const char* source; bool assigned; bool strict; } outers[] = {
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after
5101 "export default 42", 5037 "export default 42",
5102 "var x; export default x = 7", 5038 "var x; export default x = 7",
5103 "export { Q } from 'somemodule.js';", 5039 "export { Q } from 'somemodule.js';",
5104 "export * from 'somemodule.js';", 5040 "export * from 'somemodule.js';",
5105 "var foo; export { foo as for };", 5041 "var foo; export { foo as for };",
5106 "export { arguments } from 'm.js';", 5042 "export { arguments } from 'm.js';",
5107 "export { for } from 'm.js';", 5043 "export { for } from 'm.js';",
5108 "export { yield } from 'm.js'", 5044 "export { yield } from 'm.js'",
5109 "export { static } from 'm.js'", 5045 "export { static } from 'm.js'",
5110 "export { let } from 'm.js'", 5046 "export { let } from 'm.js'",
5047 "var a; export { a as b, a as c };",
5111 5048
5112 "import 'somemodule.js';", 5049 "import 'somemodule.js';",
5113 "import { } from 'm.js';", 5050 "import { } from 'm.js';",
5114 "import { a } from 'm.js';", 5051 "import { a } from 'm.js';",
5115 "import { a, b as d, c, } from 'm.js';", 5052 "import { a, b as d, c, } from 'm.js';",
5116 "import * as thing from 'm.js';", 5053 "import * as thing from 'm.js';",
5117 "import thing from 'm.js';", 5054 "import thing from 'm.js';",
5118 "import thing, * as rest from 'm.js';", 5055 "import thing, * as rest from 'm.js';",
5119 "import thing, { a, b, c } from 'm.js';", 5056 "import thing, { a, b, c } from 'm.js';",
5120 "import { arguments as a } from 'm.js';", 5057 "import { arguments as a } from 'm.js';",
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
5204 "export default const x = 7;", 5141 "export default const x = 7;",
5205 "export *;", 5142 "export *;",
5206 "export * from;", 5143 "export * from;",
5207 "export { Q } from;", 5144 "export { Q } from;",
5208 "export default from 'module.js';", 5145 "export default from 'module.js';",
5209 "export { for }", 5146 "export { for }",
5210 "export { for as foo }", 5147 "export { for as foo }",
5211 "export { arguments }", 5148 "export { arguments }",
5212 "export { arguments as foo }", 5149 "export { arguments as foo }",
5213 "var a; export { a, a };", 5150 "var a; export { a, a };",
5151 "var a, b; export { a as b, b };",
5152 "var a, b; export { a as c, b as c };",
5153 "export default function f(){}; export default class C {};",
5154 "export default function f(){}; var a; export { a as default };",
5214 5155
5215 "import from;", 5156 "import from;",
5216 "import from 'm.js';", 5157 "import from 'm.js';",
5217 "import { };", 5158 "import { };",
5218 "import {;", 5159 "import {;",
5219 "import };", 5160 "import };",
5220 "import { , };", 5161 "import { , };",
5221 "import { , } from 'm.js';", 5162 "import { , } from 'm.js';",
5222 "import { a } from;", 5163 "import { a } from;",
5223 "import { a } 'm.js';", 5164 "import { a } 'm.js';",
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
5541 static const ParserFlag always_flags[] = { 5482 static const ParserFlag always_flags[] = {
5542 kAllowStrongMode, kAllowHarmonyScoping 5483 kAllowStrongMode, kAllowHarmonyScoping
5543 }; 5484 };
5544 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 5485 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
5545 arraysize(always_flags)); 5486 arraysize(always_flags));
5546 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5487 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5547 arraysize(always_flags)); 5488 arraysize(always_flags));
5548 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5489 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5549 arraysize(always_flags)); 5490 arraysize(always_flags));
5550 } 5491 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698