OLD | NEW |
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 Loading... |
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::Isolate* isolate = v8::Isolate::GetCurrent(); | 176 v8::Isolate* isolate = CcTest::isolate(); |
177 v8::HandleScope handles(isolate); | 177 v8::HandleScope handles(isolate); |
178 v8::Local<v8::Context> context = v8::Context::New(isolate); | 178 v8::Local<v8::Context> context = v8::Context::New(isolate); |
179 v8::Context::Scope context_scope(context); | 179 v8::Context::Scope context_scope(context); |
180 int marker; | 180 int marker; |
181 i::Isolate::Current()->stack_guard()->SetStackLimit( | 181 i::Isolate::Current()->stack_guard()->SetStackLimit( |
182 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 182 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
183 | 183 |
184 // Source containing functions that might be lazily compiled and all types | 184 // Source containing functions that might be lazily compiled and all types |
185 // of symbols (string, propertyName, regexp). | 185 // of symbols (string, propertyName, regexp). |
186 const char* source = | 186 const char* source = |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // the block could be lazily compiled, and an extra, unexpected, | 345 // the block could be lazily compiled, and an extra, unexpected, |
346 // entry was added to the data. | 346 // entry was added to the data. |
347 int marker; | 347 int marker; |
348 isolate->stack_guard()->SetStackLimit( | 348 isolate->stack_guard()->SetStackLimit( |
349 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 349 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
350 | 350 |
351 const char* program = | 351 const char* program = |
352 "try { } catch (e) { var foo = function () { /* first */ } }" | 352 "try { } catch (e) { var foo = function () { /* first */ } }" |
353 "var bar = function () { /* second */ }"; | 353 "var bar = function () { /* second */ }"; |
354 | 354 |
355 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 355 v8::HandleScope handles(CcTest::isolate()); |
356 i::Handle<i::String> source( | 356 i::Handle<i::String> source( |
357 factory->NewStringFromAscii(i::CStrVector(program))); | 357 factory->NewStringFromAscii(i::CStrVector(program))); |
358 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 358 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
359 i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, &stream); | 359 i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, &stream); |
360 CHECK(!data->HasError()); | 360 CHECK(!data->HasError()); |
361 | 361 |
362 data->Initialize(); | 362 data->Initialize(); |
363 | 363 |
364 int first_function = | 364 int first_function = |
365 static_cast<int>(strstr(program, "function") - program); | 365 static_cast<int>(strstr(program, "function") - program); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::Isolate* isolate = v8::Isolate::GetCurrent(); | 547 v8::Isolate* isolate = CcTest::isolate(); |
548 v8::HandleScope handles(isolate); | 548 v8::HandleScope handles(isolate); |
549 v8::Local<v8::Context> context = v8::Context::New(isolate); | 549 v8::Local<v8::Context> context = v8::Context::New(isolate); |
550 v8::Context::Scope context_scope(context); | 550 v8::Context::Scope context_scope(context); |
551 | 551 |
552 TestCharacterStream("abc\0\n\r\x7f", 7); | 552 TestCharacterStream("abc\0\n\r\x7f", 7); |
553 static const unsigned kBigStringSize = 4096; | 553 static const unsigned kBigStringSize = 4096; |
554 char buffer[kBigStringSize + 1]; | 554 char buffer[kBigStringSize + 1]; |
555 for (unsigned i = 0; i < kBigStringSize; i++) { | 555 for (unsigned i = 0; i < kBigStringSize; i++) { |
556 buffer[i] = static_cast<char>(i & 0x7f); | 556 buffer[i] = static_cast<char>(i & 0x7f); |
557 } | 557 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, | 986 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
987 { " 'foo';\n" | 987 { " 'foo';\n" |
988 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", | 988 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", |
989 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, | 989 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
990 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } | 990 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } |
991 }; | 991 }; |
992 | 992 |
993 i::Isolate* isolate = i::Isolate::Current(); | 993 i::Isolate* isolate = i::Isolate::Current(); |
994 i::Factory* factory = isolate->factory(); | 994 i::Factory* factory = isolate->factory(); |
995 | 995 |
996 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 996 v8::HandleScope handles(CcTest::isolate()); |
997 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent()); | 997 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
998 v8::Context::Scope context_scope(context); | 998 v8::Context::Scope context_scope(context); |
999 | 999 |
1000 int marker; | 1000 int marker; |
1001 isolate->stack_guard()->SetStackLimit( | 1001 isolate->stack_guard()->SetStackLimit( |
1002 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 1002 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
1003 | 1003 |
1004 for (int i = 0; source_data[i].outer_prefix; i++) { | 1004 for (int i = 0; source_data[i].outer_prefix; i++) { |
1005 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); | 1005 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); |
1006 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); | 1006 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); |
1007 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); | 1007 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 ";", | 1260 ";", |
1261 "\n", | 1261 "\n", |
1262 ";\n", | 1262 ";\n", |
1263 "\n;", | 1263 "\n;", |
1264 NULL | 1264 NULL |
1265 }; | 1265 }; |
1266 | 1266 |
1267 i::Isolate* isolate = i::Isolate::Current(); | 1267 i::Isolate* isolate = i::Isolate::Current(); |
1268 i::Factory* factory = isolate->factory(); | 1268 i::Factory* factory = isolate->factory(); |
1269 | 1269 |
1270 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 1270 v8::HandleScope handles(CcTest::isolate()); |
1271 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent()); | 1271 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1272 v8::Context::Scope context_scope(context); | 1272 v8::Context::Scope context_scope(context); |
1273 | 1273 |
1274 int marker; | 1274 int marker; |
1275 isolate->stack_guard()->SetStackLimit( | 1275 isolate->stack_guard()->SetStackLimit( |
1276 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 1276 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
1277 | 1277 |
1278 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1278 for (int i = 0; context_data[i][0] != NULL; ++i) { |
1279 for (int j = 0; statement_data[j] != NULL; ++j) { | 1279 for (int j = 0; statement_data[j] != NULL; ++j) { |
1280 for (int k = 0; termination_data[k] != NULL; ++k) { | 1280 for (int k = 0; termination_data[k] != NULL; ++k) { |
1281 int kPrefixLen = i::StrLength(context_data[i][0]); | 1281 int kPrefixLen = i::StrLength(context_data[i][0]); |
(...skipping 19 matching lines...) Expand all Loading... |
1301 } | 1301 } |
1302 } | 1302 } |
1303 } | 1303 } |
1304 | 1304 |
1305 | 1305 |
1306 TEST(PreparserStrictOctal) { | 1306 TEST(PreparserStrictOctal) { |
1307 // Test that syntax error caused by octal literal is reported correctly as | 1307 // Test that syntax error caused by octal literal is reported correctly as |
1308 // such (issue 2220). | 1308 // such (issue 2220). |
1309 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. | 1309 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. |
1310 v8::V8::Initialize(); | 1310 v8::V8::Initialize(); |
1311 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1311 v8::HandleScope scope(CcTest::isolate()); |
1312 v8::Context::Scope context_scope( | 1312 v8::Context::Scope context_scope( |
1313 v8::Context::New(v8::Isolate::GetCurrent())); | 1313 v8::Context::New(CcTest::isolate())); |
1314 v8::TryCatch try_catch; | 1314 v8::TryCatch try_catch; |
1315 const char* script = | 1315 const char* script = |
1316 "\"use strict\"; \n" | 1316 "\"use strict\"; \n" |
1317 "a = function() { \n" | 1317 "a = function() { \n" |
1318 " b = function() { \n" | 1318 " b = function() { \n" |
1319 " 01; \n" | 1319 " 01; \n" |
1320 " }; \n" | 1320 " }; \n" |
1321 "}; \n"; | 1321 "}; \n"; |
1322 v8::Script::Compile(v8::String::New(script)); | 1322 v8::Script::Compile(v8::String::New(script)); |
1323 CHECK(try_catch.HasCaught()); | 1323 CHECK(try_catch.HasCaught()); |
1324 v8::String::Utf8Value exception(try_catch.Exception()); | 1324 v8::String::Utf8Value exception(try_catch.Exception()); |
1325 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1325 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
1326 *exception); | 1326 *exception); |
1327 } | 1327 } |
OLD | NEW |