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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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 | Annotate | Revision Log
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 const char* data() const { return data_; } 166 const char* data() const { return data_; }
167 size_t length() const { return length_; } 167 size_t length() const { return length_; }
168 168
169 private: 169 private:
170 const char* data_; 170 const char* data_;
171 size_t length_; 171 size_t length_;
172 }; 172 };
173 173
174 174
175 TEST(Preparsing) { 175 TEST(Preparsing) {
176 v8::HandleScope handles; 176 v8::HandleScope handles(v8::Isolate::GetCurrent());
177 v8::Persistent<v8::Context> context = v8::Context::New(); 177 v8::Persistent<v8::Context> context = v8::Context::New();
178 v8::Context::Scope context_scope(context); 178 v8::Context::Scope context_scope(context);
179 int marker; 179 int marker;
180 i::Isolate::Current()->stack_guard()->SetStackLimit( 180 i::Isolate::Current()->stack_guard()->SetStackLimit(
181 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 181 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
182 182
183 // Source containing functions that might be lazily compiled and all types 183 // Source containing functions that might be lazily compiled and all types
184 // of symbols (string, propertyName, regexp). 184 // of symbols (string, propertyName, regexp).
185 const char* source = 185 const char* source =
186 "var x = 42;" 186 "var x = 42;"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // the block could be lazily compiled, and an extra, unexpected, 344 // the block could be lazily compiled, and an extra, unexpected,
345 // entry was added to the data. 345 // entry was added to the data.
346 int marker; 346 int marker;
347 i::Isolate::Current()->stack_guard()->SetStackLimit( 347 i::Isolate::Current()->stack_guard()->SetStackLimit(
348 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 348 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
349 349
350 const char* program = 350 const char* program =
351 "try { } catch (e) { var foo = function () { /* first */ } }" 351 "try { } catch (e) { var foo = function () { /* first */ } }"
352 "var bar = function () { /* second */ }"; 352 "var bar = function () { /* second */ }";
353 353
354 v8::HandleScope handles; 354 v8::HandleScope handles(v8::Isolate::GetCurrent());
355 i::Handle<i::String> source( 355 i::Handle<i::String> source(
356 FACTORY->NewStringFromAscii(i::CStrVector(program))); 356 FACTORY->NewStringFromAscii(i::CStrVector(program)));
357 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 357 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
358 i::ScriptDataImpl* data = i::ParserApi::PreParse(&stream, NULL, false); 358 i::ScriptDataImpl* data = i::ParserApi::PreParse(&stream, NULL, false);
359 CHECK(!data->HasError()); 359 CHECK(!data->HasError());
360 360
361 data->Initialize(); 361 data->Initialize();
362 362
363 int first_function = 363 int first_function =
364 static_cast<int>(strstr(program, "function") - program); 364 static_cast<int>(strstr(program, "function") - program);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 int32_t c1 = uc16_stream.Advance(); 537 int32_t c1 = uc16_stream.Advance();
538 int32_t c2 = string_stream.Advance(); 538 int32_t c2 = string_stream.Advance();
539 int32_t c3 = utf8_stream.Advance(); 539 int32_t c3 = utf8_stream.Advance();
540 CHECK_LT(c1, 0); 540 CHECK_LT(c1, 0);
541 CHECK_LT(c2, 0); 541 CHECK_LT(c2, 0);
542 CHECK_LT(c3, 0); 542 CHECK_LT(c3, 0);
543 } 543 }
544 544
545 545
546 TEST(CharacterStreams) { 546 TEST(CharacterStreams) {
547 v8::HandleScope handles; 547 v8::HandleScope handles(v8::Isolate::GetCurrent());
548 v8::Persistent<v8::Context> context = v8::Context::New(); 548 v8::Persistent<v8::Context> context = v8::Context::New();
549 v8::Context::Scope context_scope(context); 549 v8::Context::Scope context_scope(context);
550 550
551 TestCharacterStream("abc\0\n\r\x7f", 7); 551 TestCharacterStream("abc\0\n\r\x7f", 7);
552 static const unsigned kBigStringSize = 4096; 552 static const unsigned kBigStringSize = 4096;
553 char buffer[kBigStringSize + 1]; 553 char buffer[kBigStringSize + 1];
554 for (unsigned i = 0; i < kBigStringSize; i++) { 554 for (unsigned i = 0; i < kBigStringSize; i++) {
555 buffer[i] = static_cast<char>(i & 0x7f); 555 buffer[i] = static_cast<char>(i & 0x7f);
556 } 556 }
557 TestCharacterStream(buffer, kBigStringSize); 557 TestCharacterStream(buffer, kBigStringSize);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, 981 i::FUNCTION_SCOPE, i::CLASSIC_MODE },
982 { " 'foo';\n" 982 { " 'foo';\n"
983 " (function fun", "(a,b) { 'bar\355\240\201\355\260\213'; }", ")();", 983 " (function fun", "(a,b) { 'bar\355\240\201\355\260\213'; }", ")();",
984 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, 984 i::FUNCTION_SCOPE, i::CLASSIC_MODE },
985 { " 'foo';\n" 985 { " 'foo';\n"
986 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", 986 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();",
987 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, 987 i::FUNCTION_SCOPE, i::CLASSIC_MODE },
988 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } 988 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE }
989 }; 989 };
990 990
991 v8::HandleScope handles; 991 v8::HandleScope handles(v8::Isolate::GetCurrent());
992 v8::Persistent<v8::Context> context = v8::Context::New(); 992 v8::Persistent<v8::Context> context = v8::Context::New();
993 v8::Context::Scope context_scope(context); 993 v8::Context::Scope context_scope(context);
994 994
995 int marker; 995 int marker;
996 i::Isolate::Current()->stack_guard()->SetStackLimit( 996 i::Isolate::Current()->stack_guard()->SetStackLimit(
997 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 997 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
998 i::FLAG_harmony_scoping = true; 998 i::FLAG_harmony_scoping = true;
999 999
1000 for (int i = 0; source_data[i].outer_prefix; i++) { 1000 for (int i = 0; source_data[i].outer_prefix; i++) {
1001 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); 1001 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix);
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 1219
1220 const char* termination_data[] = { 1220 const char* termination_data[] = {
1221 "", 1221 "",
1222 ";", 1222 ";",
1223 "\n", 1223 "\n",
1224 ";\n", 1224 ";\n",
1225 "\n;", 1225 "\n;",
1226 NULL 1226 NULL
1227 }; 1227 };
1228 1228
1229 v8::HandleScope handles; 1229 v8::HandleScope handles(v8::Isolate::GetCurrent());
1230 v8::Persistent<v8::Context> context = v8::Context::New(); 1230 v8::Persistent<v8::Context> context = v8::Context::New();
1231 v8::Context::Scope context_scope(context); 1231 v8::Context::Scope context_scope(context);
1232 1232
1233 int marker; 1233 int marker;
1234 i::Isolate::Current()->stack_guard()->SetStackLimit( 1234 i::Isolate::Current()->stack_guard()->SetStackLimit(
1235 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1235 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1236 1236
1237 for (int i = 0; context_data[i][0] != NULL; ++i) { 1237 for (int i = 0; context_data[i][0] != NULL; ++i) {
1238 for (int j = 0; statement_data[j] != NULL; ++j) { 1238 for (int j = 0; statement_data[j] != NULL; ++j) {
1239 for (int k = 0; termination_data[k] != NULL; ++k) { 1239 for (int k = 0; termination_data[k] != NULL; ++k) {
(...skipping 20 matching lines...) Expand all
1260 } 1260 }
1261 } 1261 }
1262 } 1262 }
1263 1263
1264 1264
1265 TEST(PreparserStrictOctal) { 1265 TEST(PreparserStrictOctal) {
1266 // Test that syntax error caused by octal literal is reported correctly as 1266 // Test that syntax error caused by octal literal is reported correctly as
1267 // such (issue 2220). 1267 // such (issue 2220).
1268 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. 1268 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing.
1269 v8::V8::Initialize(); 1269 v8::V8::Initialize();
1270 v8::HandleScope scope; 1270 v8::HandleScope scope(v8::Isolate::GetCurrent());
1271 v8::Context::Scope context_scope(v8::Context::New()); 1271 v8::Context::Scope context_scope(v8::Context::New());
1272 v8::TryCatch try_catch; 1272 v8::TryCatch try_catch;
1273 const char* script = 1273 const char* script =
1274 "\"use strict\"; \n" 1274 "\"use strict\"; \n"
1275 "a = function() { \n" 1275 "a = function() { \n"
1276 " b = function() { \n" 1276 " b = function() { \n"
1277 " 01; \n" 1277 " 01; \n"
1278 " }; \n" 1278 " }; \n"
1279 "}; \n"; 1279 "}; \n";
1280 v8::Script::Compile(v8::String::New(script)); 1280 v8::Script::Compile(v8::String::New(script));
1281 CHECK(try_catch.HasCaught()); 1281 CHECK(try_catch.HasCaught());
1282 v8::String::Utf8Value exception(try_catch.Exception()); 1282 v8::String::Utf8Value exception(try_catch.Exception());
1283 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1283 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1284 *exception); 1284 *exception);
1285 } 1285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698