Revision f230a1cf deps/v8/test/cctest/test-parsing.cc

View differences:

deps/v8/test/cctest/test-parsing.cc
107 107

  
108 108
TEST(ScanHTMLEndComments) {
109 109
  v8::V8::Initialize();
110
  v8::Isolate* isolate = CcTest::isolate();
110 111

  
111 112
  // Regression test. See:
112 113
  //    http://code.google.com/p/chromium/issues/detail?id=53548
......
139 140

  
140 141
  // Parser/Scanner needs a stack limit.
141 142
  int marker;
142
  i::Isolate::Current()->stack_guard()->SetStackLimit(
143
  CcTest::i_isolate()->stack_guard()->SetStackLimit(
143 144
      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
144 145

  
145 146
  for (int i = 0; tests[i]; i++) {
146 147
    v8::ScriptData* data =
147
        v8::ScriptData::PreCompile(tests[i], i::StrLength(tests[i]));
148
        v8::ScriptData::PreCompile(isolate, tests[i], i::StrLength(tests[i]));
148 149
    CHECK(data != NULL && !data->HasError());
149 150
    delete data;
150 151
  }
151 152

  
152 153
  for (int i = 0; fail_tests[i]; i++) {
153
    v8::ScriptData* data =
154
        v8::ScriptData::PreCompile(fail_tests[i], i::StrLength(fail_tests[i]));
154
    v8::ScriptData* data = v8::ScriptData::PreCompile(
155
        isolate, fail_tests[i], i::StrLength(fail_tests[i]));
155 156
    CHECK(data == NULL || data->HasError());
156 157
    delete data;
157 158
  }
......
173 174

  
174 175

  
175 176
TEST(Preparsing) {
176
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
177
  v8::Isolate* isolate = CcTest::isolate();
177 178
  v8::HandleScope handles(isolate);
178 179
  v8::Local<v8::Context> context = v8::Context::New(isolate);
179 180
  v8::Context::Scope context_scope(context);
180 181
  int marker;
181
  i::Isolate::Current()->stack_guard()->SetStackLimit(
182
  CcTest::i_isolate()->stack_guard()->SetStackLimit(
182 183
      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
183 184

  
184 185
  // Source containing functions that might be lazily compiled  and all types
......
199 200
  int error_source_length = i::StrLength(error_source);
200 201

  
201 202
  v8::ScriptData* preparse =
202
      v8::ScriptData::PreCompile(source, source_length);
203
      v8::ScriptData::PreCompile(isolate, source, source_length);
203 204
  CHECK(!preparse->HasError());
204 205
  bool lazy_flag = i::FLAG_lazy;
205 206
  {
......
221 222

  
222 223
  // Syntax error.
223 224
  v8::ScriptData* error_preparse =
224
      v8::ScriptData::PreCompile(error_source, error_source_length);
225
      v8::ScriptData::PreCompile(isolate, error_source, error_source_length);
225 226
  CHECK(error_preparse->HasError());
226 227
  i::ScriptDataImpl *pre_impl =
227 228
      reinterpret_cast<i::ScriptDataImpl*>(error_preparse);
......
241 242
  v8::V8::Initialize();
242 243

  
243 244
  int marker;
244
  i::Isolate::Current()->stack_guard()->SetStackLimit(
245
  CcTest::i_isolate()->stack_guard()->SetStackLimit(
245 246
      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
246 247

  
247 248
  const char* programs[] = {
......
253 254
      NULL
254 255
  };
255 256

  
256
  uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit();
257
  uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
257 258
  for (int i = 0; programs[i]; i++) {
258 259
    const char* program = programs[i];
259 260
    i::Utf8ToUtf16CharacterStream stream(
260 261
        reinterpret_cast<const i::byte*>(program),
261 262
        static_cast<unsigned>(strlen(program)));
262 263
    i::CompleteParserRecorder log;
263
    i::Scanner scanner(i::Isolate::Current()->unicode_cache());
264
    i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
264 265
    scanner.Initialize(&stream);
265 266

  
266
    v8::preparser::PreParser preparser(&scanner, &log, stack_limit);
267
    i::PreParser preparser(&scanner, &log, stack_limit);
267 268
    preparser.set_allow_lazy(true);
268 269
    preparser.set_allow_natives_syntax(true);
269
    v8::preparser::PreParser::PreParseResult result =
270
        preparser.PreParseProgram();
271
    CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
270
    i::PreParser::PreParseResult result = preparser.PreParseProgram();
271
    CHECK_EQ(i::PreParser::kPreParseSuccess, result);
272 272
    i::ScriptDataImpl data(log.ExtractData());
273 273
    CHECK(!data.has_error());
274 274
  }
......
279 279
  v8::V8::Initialize();
280 280

  
281 281
  int marker;
282
  i::Isolate::Current()->stack_guard()->SetStackLimit(
282
  CcTest::i_isolate()->stack_guard()->SetStackLimit(
283 283
      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
284 284

  
285 285
  const char* programs[] = {
......
288 288
      NULL
289 289
  };
290 290

  
291
  uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit();
291
  uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
292 292
  for (int i = 0; programs[i]; i++) {
293 293
    const char* program = programs[i];
294 294
    i::Utf8ToUtf16CharacterStream stream(
295 295
        reinterpret_cast<const i::byte*>(program),
296 296
        static_cast<unsigned>(strlen(program)));
297 297
    i::CompleteParserRecorder log;
298
    i::Scanner scanner(i::Isolate::Current()->unicode_cache());
298
    i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
299 299
    scanner.Initialize(&stream);
300 300

  
301 301
    // Preparser defaults to disallowing natives syntax.
302
    v8::preparser::PreParser preparser(&scanner, &log, stack_limit);
302
    i::PreParser preparser(&scanner, &log, stack_limit);
303 303
    preparser.set_allow_lazy(true);
304
    v8::preparser::PreParser::PreParseResult result =
305
        preparser.PreParseProgram();
306
    CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
304
    i::PreParser::PreParseResult result = preparser.PreParseProgram();
305
    CHECK_EQ(i::PreParser::kPreParseSuccess, result);
307 306
    i::ScriptDataImpl data(log.ExtractData());
308 307
    // Data contains syntax error.
309 308
    CHECK(data.has_error());
......
313 312

  
314 313
TEST(RegressChromium62639) {
315 314
  v8::V8::Initialize();
316
  i::Isolate* isolate = i::Isolate::Current();
315
  i::Isolate* isolate = CcTest::i_isolate();
317 316

  
318 317
  int marker;
319 318
  isolate->stack_guard()->SetStackLimit(
......
337 336

  
338 337
TEST(Regress928) {
339 338
  v8::V8::Initialize();
340
  i::Isolate* isolate = i::Isolate::Current();
339
  i::Isolate* isolate = CcTest::i_isolate();
341 340
  i::Factory* factory = isolate->factory();
342 341

  
343 342
  // Preparsing didn't consider the catch clause of a try statement
......
352 351
      "try { } catch (e) { var foo = function () { /* first */ } }"
353 352
      "var bar = function () { /* second */ }";
354 353

  
355
  v8::HandleScope handles(v8::Isolate::GetCurrent());
354
  v8::HandleScope handles(CcTest::isolate());
356 355
  i::Handle<i::String> source(
357 356
      factory->NewStringFromAscii(i::CStrVector(program)));
358 357
  i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
......
384 383
  v8::V8::Initialize();
385 384

  
386 385
  int marker;
387
  i::Isolate::Current()->stack_guard()->SetStackLimit(
386
  CcTest::i_isolate()->stack_guard()->SetStackLimit(
388 387
      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
389 388

  
390 389
  size_t kProgramSize = 1024 * 1024;
......
392 391
  memset(*program, '(', kProgramSize);
393 392
  program[kProgramSize] = '\0';
394 393

  
395
  uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit();
394
  uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
396 395

  
397 396
  i::Utf8ToUtf16CharacterStream stream(
398 397
      reinterpret_cast<const i::byte*>(*program),
399 398
      static_cast<unsigned>(kProgramSize));
400 399
  i::CompleteParserRecorder log;
401
  i::Scanner scanner(i::Isolate::Current()->unicode_cache());
400
  i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
402 401
  scanner.Initialize(&stream);
403 402

  
404
  v8::preparser::PreParser preparser(&scanner, &log, stack_limit);
403
  i::PreParser preparser(&scanner, &log, stack_limit);
405 404
  preparser.set_allow_lazy(true);
406
  v8::preparser::PreParser::PreParseResult result =
407
      preparser.PreParseProgram();
408
  CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result);
405
  i::PreParser::PreParseResult result = preparser.PreParseProgram();
406
  CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
409 407
}
410 408

  
411 409

  
......
437 435
                         unsigned end = 0) {
438 436
  if (end == 0) end = length;
439 437
  unsigned sub_length = end - start;
440
  i::Isolate* isolate = i::Isolate::Current();
438
  i::Isolate* isolate = CcTest::i_isolate();
441 439
  i::Factory* factory = isolate->factory();
442 440
  i::HandleScope test_scope(isolate);
443 441
  i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]);
......
544 542

  
545 543

  
546 544
TEST(CharacterStreams) {
547
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
545
  v8::Isolate* isolate = CcTest::isolate();
548 546
  v8::HandleScope handles(isolate);
549 547
  v8::Local<v8::Context> context = v8::Context::New(isolate);
550 548
  v8::Context::Scope context_scope(context);
......
619 617
                       i::Token::Value* expected_tokens,
620 618
                       int skip_pos = 0,  // Zero means not skipping.
621 619
                       int skip_to = 0) {
622
  i::Scanner scanner(i::Isolate::Current()->unicode_cache());
620
  i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
623 621
  scanner.Initialize(stream);
624 622

  
625 623
  int i = 0;
......
701 699
  i::Utf8ToUtf16CharacterStream stream(
702 700
       reinterpret_cast<const i::byte*>(re_source),
703 701
       static_cast<unsigned>(strlen(re_source)));
704
  i::Scanner scanner(i::Isolate::Current()->unicode_cache());
702
  i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
705 703
  scanner.Initialize(&stream);
706 704

  
707 705
  i::Token::Value start = scanner.peek();
......
990 988
    { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE }
991 989
  };
992 990

  
993
  i::Isolate* isolate = i::Isolate::Current();
991
  i::Isolate* isolate = CcTest::i_isolate();
994 992
  i::Factory* factory = isolate->factory();
995 993

  
996
  v8::HandleScope handles(v8::Isolate::GetCurrent());
997
  v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent());
994
  v8::HandleScope handles(CcTest::isolate());
995
  v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
998 996
  v8::Context::Scope context_scope(context);
999 997

  
1000 998
  int marker;
......
1027 1025
    parser.set_allow_harmony_scoping(true);
1028 1026
    info.MarkAsGlobal();
1029 1027
    info.SetLanguageMode(source_data[i].language_mode);
1030
    i::FunctionLiteral* function = parser.ParseProgram();
1031
    CHECK(function != NULL);
1028
    parser.Parse();
1029
    CHECK(info.function() != NULL);
1032 1030

  
1033 1031
    // Check scope types and positions.
1034
    i::Scope* scope = function->scope();
1032
    i::Scope* scope = info.function()->scope();
1035 1033
    CHECK(scope->is_global_scope());
1036 1034
    CHECK_EQ(scope->start_position(), 0);
1037 1035
    CHECK_EQ(scope->end_position(), kProgramSize);
......
1048 1046

  
1049 1047

  
1050 1048
i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) {
1051
  i::Isolate* isolate = i::Isolate::Current();
1049
  i::Isolate* isolate = CcTest::i_isolate();
1052 1050
  i::Factory* factory = isolate->factory();
1053 1051
  const char* message = data->BuildMessage();
1054 1052
  i::Handle<i::String> format = v8::Utils::OpenHandle(
......
1087 1085
  kAllowModules,
1088 1086
  kAllowGenerators,
1089 1087
  kAllowForOf,
1090
  kAllowHarmonyNumericLiterals,
1091
  kParserFlagCount
1088
  kAllowHarmonyNumericLiterals
1092 1089
};
1093 1090

  
1094 1091

  
1095
static bool checkParserFlag(unsigned flags, ParserFlag flag) {
1096
  return flags & (1 << flag);
1092
void SetParserFlags(i::ParserBase* parser, i::EnumSet<ParserFlag> flags) {
1093
  parser->set_allow_lazy(flags.Contains(kAllowLazy));
1094
  parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1095
  parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1096
  parser->set_allow_modules(flags.Contains(kAllowModules));
1097
  parser->set_allow_generators(flags.Contains(kAllowGenerators));
1098
  parser->set_allow_for_of(flags.Contains(kAllowForOf));
1099
  parser->set_allow_harmony_numeric_literals(
1100
      flags.Contains(kAllowHarmonyNumericLiterals));
1097 1101
}
1098 1102

  
1099 1103

  
1100
#define SET_PARSER_FLAGS(parser, flags) \
1101
  parser.set_allow_lazy(checkParserFlag(flags, kAllowLazy)); \
1102
  parser.set_allow_natives_syntax(checkParserFlag(flags, \
1103
                                                  kAllowNativesSyntax)); \
1104
  parser.set_allow_harmony_scoping(checkParserFlag(flags, \
1105
                                                   kAllowHarmonyScoping)); \
1106
  parser.set_allow_modules(checkParserFlag(flags, kAllowModules)); \
1107
  parser.set_allow_generators(checkParserFlag(flags, kAllowGenerators)); \
1108
  parser.set_allow_for_of(checkParserFlag(flags, kAllowForOf)); \
1109
  parser.set_allow_harmony_numeric_literals( \
1110
      checkParserFlag(flags, kAllowHarmonyNumericLiterals));
1111

  
1112
void TestParserSyncWithFlags(i::Handle<i::String> source, unsigned flags) {
1113
  i::Isolate* isolate = i::Isolate::Current();
1104
void TestParserSyncWithFlags(i::Handle<i::String> source,
1105
                             i::EnumSet<ParserFlag> flags) {
1106
  i::Isolate* isolate = CcTest::i_isolate();
1114 1107
  i::Factory* factory = isolate->factory();
1115 1108

  
1116 1109
  uintptr_t stack_limit = isolate->stack_guard()->real_climit();
......
1120 1113
  {
1121 1114
    i::Scanner scanner(isolate->unicode_cache());
1122 1115
    i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1123
    v8::preparser::PreParser preparser(&scanner, &log, stack_limit);
1124
    SET_PARSER_FLAGS(preparser, flags);
1116
    i::PreParser preparser(&scanner, &log, stack_limit);
1117
    SetParserFlags(&preparser, flags);
1125 1118
    scanner.Initialize(&stream);
1126
    v8::preparser::PreParser::PreParseResult result =
1127
        preparser.PreParseProgram();
1128
    CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
1119
    i::PreParser::PreParseResult result = preparser.PreParseProgram();
1120
    CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1129 1121
  }
1130 1122
  i::ScriptDataImpl data(log.ExtractData());
1131 1123

  
......
1135 1127
    i::Handle<i::Script> script = factory->NewScript(source);
1136 1128
    i::CompilationInfoWithZone info(script);
1137 1129
    i::Parser parser(&info);
1138
    SET_PARSER_FLAGS(parser, flags);
1130
    SetParserFlags(&parser, flags);
1139 1131
    info.MarkAsGlobal();
1140
    function = parser.ParseProgram();
1132
    parser.Parse();
1133
    function = info.function();
1141 1134
  }
1142 1135

  
1143 1136
  // Check that preparsing fails iff parsing fails.
......
1188 1181
}
1189 1182

  
1190 1183

  
1191
void TestParserSync(i::Handle<i::String> source) {
1192
  for (unsigned flags = 0; flags < (1 << kParserFlagCount); ++flags) {
1193
    TestParserSyncWithFlags(source, flags);
1184
void TestParserSync(const char* source,
1185
                    const ParserFlag* flag_list,
1186
                    size_t flag_list_length) {
1187
  i::Handle<i::String> str =
1188
      CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source));
1189
  for (int bits = 0; bits < (1 << flag_list_length); bits++) {
1190
    i::EnumSet<ParserFlag> flags;
1191
    for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) {
1192
      if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]);
1193
    }
1194
    TestParserSyncWithFlags(str, flags);
1194 1195
  }
1195 1196
}
1196 1197

  
......
1264 1265
    NULL
1265 1266
  };
1266 1267

  
1267
  i::Isolate* isolate = i::Isolate::Current();
1268
  i::Factory* factory = isolate->factory();
1269

  
1270
  v8::HandleScope handles(v8::Isolate::GetCurrent());
1271
  v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent());
1268
  v8::HandleScope handles(CcTest::isolate());
1269
  v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1272 1270
  v8::Context::Scope context_scope(context);
1273 1271

  
1274 1272
  int marker;
1275
  isolate->stack_guard()->SetStackLimit(
1273
  CcTest::i_isolate()->stack_guard()->SetStackLimit(
1276 1274
      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1277 1275

  
1276
  static const ParserFlag flags1[] = {
1277
    kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1278
    kAllowForOf
1279
  };
1278 1280
  for (int i = 0; context_data[i][0] != NULL; ++i) {
1279 1281
    for (int j = 0; statement_data[j] != NULL; ++j) {
1280 1282
      for (int k = 0; termination_data[k] != NULL; ++k) {
......
1294 1296
            termination_data[k],
1295 1297
            context_data[i][1]);
1296 1298
        CHECK(length == kProgramSize);
1297
        i::Handle<i::String> source =
1298
            factory->NewStringFromAscii(i::CStrVector(program.start()));
1299
        TestParserSync(source);
1299
        TestParserSync(program.start(), flags1, ARRAY_SIZE(flags1));
1300 1300
      }
1301 1301
    }
1302 1302
  }
1303

  
1304
  // Neither Harmony numeric literals nor our natives syntax have any
1305
  // interaction with the flags above, so test these separately to reduce
1306
  // the combinatorial explosion.
1307
  static const ParserFlag flags2[] = { kAllowHarmonyNumericLiterals };
1308
  TestParserSync("0o1234", flags2, ARRAY_SIZE(flags2));
1309
  TestParserSync("0b1011", flags2, ARRAY_SIZE(flags2));
1310

  
1311
  static const ParserFlag flags3[] = { kAllowNativesSyntax };
1312
  TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3));
1303 1313
}
1304 1314

  
1305 1315

  
......
1308 1318
  // such (issue 2220).
1309 1319
  v8::internal::FLAG_min_preparse_length = 1;  // Force preparsing.
1310 1320
  v8::V8::Initialize();
1311
  v8::HandleScope scope(v8::Isolate::GetCurrent());
1321
  v8::HandleScope scope(CcTest::isolate());
1312 1322
  v8::Context::Scope context_scope(
1313
      v8::Context::New(v8::Isolate::GetCurrent()));
1323
      v8::Context::New(CcTest::isolate()));
1314 1324
  v8::TryCatch try_catch;
1315 1325
  const char* script =
1316 1326
      "\"use strict\";       \n"

Also available in: Unified diff