| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // TODO(mythria): Remove this define after this flag is turned on globally |
| 29 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 30 |
| 28 #include <stdio.h> | 31 #include <stdio.h> |
| 29 #include <stdlib.h> | 32 #include <stdlib.h> |
| 30 #include <string.h> | 33 #include <string.h> |
| 31 | 34 |
| 32 #include "src/v8.h" | 35 #include "src/v8.h" |
| 33 | 36 |
| 34 #include "src/ast.h" | 37 #include "src/ast.h" |
| 35 #include "src/ast-numbering.h" | 38 #include "src/ast-numbering.h" |
| 36 #include "src/ast-value-factory.h" | 39 #include "src/ast-value-factory.h" |
| 37 #include "src/compiler.h" | 40 #include "src/compiler.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 " f\\u006fr: 'keyword propertyname with escape'};" | 221 " f\\u006fr: 'keyword propertyname with escape'};" |
| 219 "var v = /RegExp Literal/;" | 222 "var v = /RegExp Literal/;" |
| 220 "var w = /RegExp Literal\\u0020With Escape/gin;" | 223 "var w = /RegExp Literal\\u0020With Escape/gin;" |
| 221 "var y = { get getter() { return 42; }, " | 224 "var y = { get getter() { return 42; }, " |
| 222 " set setter(v) { this.value = v; }};" | 225 " set setter(v) { this.value = v; }};" |
| 223 "var f = a => function (b) { return a + b; };" | 226 "var f = a => function (b) { return a + b; };" |
| 224 "var g = a => b => a + b;"; | 227 "var g = a => b => a + b;"; |
| 225 int source_length = i::StrLength(source); | 228 int source_length = i::StrLength(source); |
| 226 | 229 |
| 227 // ScriptResource will be deleted when the corresponding String is GCd. | 230 // ScriptResource will be deleted when the corresponding String is GCd. |
| 228 v8::ScriptCompiler::Source script_source(v8::String::NewExternal( | 231 v8::ScriptCompiler::Source script_source( |
| 229 isolate, new ScriptResource(source, source_length))); | 232 v8::String::NewExternalOneByte(isolate, |
| 233 new ScriptResource(source, source_length)) |
| 234 .ToLocalChecked()); |
| 230 i::FLAG_min_preparse_length = 0; | 235 i::FLAG_min_preparse_length = 0; |
| 231 v8::ScriptCompiler::Compile(isolate, &script_source, | 236 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source, |
| 232 v8::ScriptCompiler::kProduceParserCache); | 237 v8::ScriptCompiler::kProduceParserCache) |
| 238 .ToLocalChecked(); |
| 233 CHECK(script_source.GetCachedData()); | 239 CHECK(script_source.GetCachedData()); |
| 234 | 240 |
| 235 // Compile the script again, using the cached data. | 241 // Compile the script again, using the cached data. |
| 236 bool lazy_flag = i::FLAG_lazy; | 242 bool lazy_flag = i::FLAG_lazy; |
| 237 i::FLAG_lazy = true; | 243 i::FLAG_lazy = true; |
| 238 v8::ScriptCompiler::Compile(isolate, &script_source, | 244 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source, |
| 239 v8::ScriptCompiler::kConsumeParserCache); | 245 v8::ScriptCompiler::kConsumeParserCache) |
| 246 .ToLocalChecked(); |
| 240 i::FLAG_lazy = false; | 247 i::FLAG_lazy = false; |
| 241 v8::ScriptCompiler::CompileUnbound(isolate, &script_source, | 248 v8::ScriptCompiler::CompileUnboundScript( |
| 242 v8::ScriptCompiler::kConsumeParserCache); | 249 isolate, &script_source, v8::ScriptCompiler::kConsumeParserCache) |
| 250 .ToLocalChecked(); |
| 243 i::FLAG_lazy = lazy_flag; | 251 i::FLAG_lazy = lazy_flag; |
| 244 } | 252 } |
| 245 | 253 |
| 246 | 254 |
| 247 TEST(PreparseFunctionDataIsUsed) { | 255 TEST(PreparseFunctionDataIsUsed) { |
| 248 // This tests that we actually do use the function data generated by the | 256 // This tests that we actually do use the function data generated by the |
| 249 // preparser. | 257 // preparser. |
| 250 | 258 |
| 251 // Make preparsing work for short scripts. | 259 // Make preparsing work for short scripts. |
| 252 i::FLAG_min_preparse_length = 0; | 260 i::FLAG_min_preparse_length = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 }; | 272 }; |
| 265 | 273 |
| 266 // Insert a syntax error inside the lazy function. | 274 // Insert a syntax error inside the lazy function. |
| 267 const char* bad_code[] = { | 275 const char* bad_code[] = { |
| 268 "function this_is_lazy() { if ( } function foo() { return 25; } foo();", | 276 "function this_is_lazy() { if ( } function foo() { return 25; } foo();", |
| 269 "var this_is_lazy = () => { if ( }; var foo = () => 25; foo();", | 277 "var this_is_lazy = () => { if ( }; var foo = () => 25; foo();", |
| 270 }; | 278 }; |
| 271 | 279 |
| 272 for (unsigned i = 0; i < arraysize(good_code); i++) { | 280 for (unsigned i = 0; i < arraysize(good_code); i++) { |
| 273 v8::ScriptCompiler::Source good_source(v8_str(good_code[i])); | 281 v8::ScriptCompiler::Source good_source(v8_str(good_code[i])); |
| 274 v8::ScriptCompiler::Compile(isolate, &good_source, | 282 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &good_source, |
| 275 v8::ScriptCompiler::kProduceParserCache); | 283 v8::ScriptCompiler::kProduceParserCache) |
| 284 .ToLocalChecked(); |
| 276 | 285 |
| 277 const v8::ScriptCompiler::CachedData* cached_data = | 286 const v8::ScriptCompiler::CachedData* cached_data = |
| 278 good_source.GetCachedData(); | 287 good_source.GetCachedData(); |
| 279 CHECK(cached_data->data != NULL); | 288 CHECK(cached_data->data != NULL); |
| 280 CHECK_GT(cached_data->length, 0); | 289 CHECK_GT(cached_data->length, 0); |
| 281 | 290 |
| 282 // Now compile the erroneous code with the good preparse data. If the | 291 // Now compile the erroneous code with the good preparse data. If the |
| 283 // preparse data is used, the lazy function is skipped and it should | 292 // preparse data is used, the lazy function is skipped and it should |
| 284 // compile fine. | 293 // compile fine. |
| 285 v8::ScriptCompiler::Source bad_source( | 294 v8::ScriptCompiler::Source bad_source( |
| 286 v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData( | 295 v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData( |
| 287 cached_data->data, cached_data->length)); | 296 cached_data->data, cached_data->length)); |
| 288 v8::Local<v8::Value> result = | 297 v8::Local<v8::Value> result = |
| 289 v8::ScriptCompiler::Compile(isolate, &bad_source, | 298 CompileRun(isolate->GetCurrentContext(), &bad_source, |
| 290 v8::ScriptCompiler::kConsumeParserCache) | 299 v8::ScriptCompiler::kConsumeParserCache); |
| 291 ->Run(); | |
| 292 CHECK(result->IsInt32()); | 300 CHECK(result->IsInt32()); |
| 293 CHECK_EQ(25, result->Int32Value()); | 301 CHECK_EQ(25, result->Int32Value(isolate->GetCurrentContext()).FromJust()); |
| 294 } | 302 } |
| 295 } | 303 } |
| 296 | 304 |
| 297 | 305 |
| 298 TEST(StandAlonePreParser) { | 306 TEST(StandAlonePreParser) { |
| 299 v8::V8::Initialize(); | 307 v8::V8::Initialize(); |
| 300 | 308 |
| 301 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 309 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 302 i::GetCurrentStackPosition() - 128 * 1024); | 310 i::GetCurrentStackPosition() - 128 * 1024); |
| 303 | 311 |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 {"eval('super.x')", EVAL}, | 1035 {"eval('super.x')", EVAL}, |
| 1028 {"eval('this.x')", EVAL}, | 1036 {"eval('this.x')", EVAL}, |
| 1029 {"eval('arguments')", EVAL}, | 1037 {"eval('arguments')", EVAL}, |
| 1030 }; | 1038 }; |
| 1031 // clang-format on | 1039 // clang-format on |
| 1032 | 1040 |
| 1033 i::Isolate* isolate = CcTest::i_isolate(); | 1041 i::Isolate* isolate = CcTest::i_isolate(); |
| 1034 i::Factory* factory = isolate->factory(); | 1042 i::Factory* factory = isolate->factory(); |
| 1035 | 1043 |
| 1036 v8::HandleScope handles(CcTest::isolate()); | 1044 v8::HandleScope handles(CcTest::isolate()); |
| 1037 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1045 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1038 v8::Context::Scope context_scope(context); | 1046 v8::Context::Scope context_scope(context); |
| 1039 | 1047 |
| 1040 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 1048 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 1041 128 * 1024); | 1049 128 * 1024); |
| 1042 | 1050 |
| 1043 for (unsigned j = 0; j < arraysize(surroundings); ++j) { | 1051 for (unsigned j = 0; j < arraysize(surroundings); ++j) { |
| 1044 for (unsigned i = 0; i < arraysize(source_data); ++i) { | 1052 for (unsigned i = 0; i < arraysize(source_data); ++i) { |
| 1045 // Super property is only allowed in constructor and method. | 1053 // Super property is only allowed in constructor and method. |
| 1046 if (((source_data[i].expected & SUPER_PROPERTY) || | 1054 if (((source_data[i].expected & SUPER_PROPERTY) || |
| 1047 (source_data[i].expected == NONE)) && j != 2) { | 1055 (source_data[i].expected == NONE)) && j != 2) { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 { " 'foo';\n" | 1340 { " 'foo';\n" |
| 1333 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", | 1341 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", |
| 1334 i::FUNCTION_SCOPE, i::SLOPPY }, | 1342 i::FUNCTION_SCOPE, i::SLOPPY }, |
| 1335 { NULL, NULL, NULL, i::EVAL_SCOPE, i::SLOPPY } | 1343 { NULL, NULL, NULL, i::EVAL_SCOPE, i::SLOPPY } |
| 1336 }; | 1344 }; |
| 1337 | 1345 |
| 1338 i::Isolate* isolate = CcTest::i_isolate(); | 1346 i::Isolate* isolate = CcTest::i_isolate(); |
| 1339 i::Factory* factory = isolate->factory(); | 1347 i::Factory* factory = isolate->factory(); |
| 1340 | 1348 |
| 1341 v8::HandleScope handles(CcTest::isolate()); | 1349 v8::HandleScope handles(CcTest::isolate()); |
| 1342 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1350 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1343 v8::Context::Scope context_scope(context); | 1351 v8::Context::Scope context_scope(context); |
| 1344 | 1352 |
| 1345 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 1353 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 1346 128 * 1024); | 1354 128 * 1024); |
| 1347 | 1355 |
| 1348 for (int i = 0; source_data[i].outer_prefix; i++) { | 1356 for (int i = 0; source_data[i].outer_prefix; i++) { |
| 1349 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); | 1357 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); |
| 1350 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); | 1358 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); |
| 1351 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); | 1359 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); |
| 1352 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); | 1360 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 i::Handle<i::String> FormatMessage(i::Vector<unsigned> data) { | 1475 i::Handle<i::String> FormatMessage(i::Vector<unsigned> data) { |
| 1468 i::Isolate* isolate = CcTest::i_isolate(); | 1476 i::Isolate* isolate = CcTest::i_isolate(); |
| 1469 int message = data[i::PreparseDataConstants::kMessageTemplatePos]; | 1477 int message = data[i::PreparseDataConstants::kMessageTemplatePos]; |
| 1470 int arg_count = data[i::PreparseDataConstants::kMessageArgCountPos]; | 1478 int arg_count = data[i::PreparseDataConstants::kMessageArgCountPos]; |
| 1471 i::Handle<i::Object> arg_object; | 1479 i::Handle<i::Object> arg_object; |
| 1472 if (arg_count == 1) { | 1480 if (arg_count == 1) { |
| 1473 // Position after text found by skipping past length field and | 1481 // Position after text found by skipping past length field and |
| 1474 // length field content words. | 1482 // length field content words. |
| 1475 const char* arg = | 1483 const char* arg = |
| 1476 ReadString(&data[i::PreparseDataConstants::kMessageArgPos]); | 1484 ReadString(&data[i::PreparseDataConstants::kMessageArgPos]); |
| 1477 arg_object = | 1485 arg_object = v8::Utils::OpenHandle(*v8_str(arg)); |
| 1478 v8::Utils::OpenHandle(*v8::String::NewFromUtf8(CcTest::isolate(), arg)); | |
| 1479 i::DeleteArray(arg); | 1486 i::DeleteArray(arg); |
| 1480 } else { | 1487 } else { |
| 1481 CHECK_EQ(0, arg_count); | 1488 CHECK_EQ(0, arg_count); |
| 1482 arg_object = isolate->factory()->undefined_value(); | 1489 arg_object = isolate->factory()->undefined_value(); |
| 1483 } | 1490 } |
| 1484 | 1491 |
| 1485 data.Dispose(); | 1492 data.Dispose(); |
| 1486 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1493 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
| 1487 } | 1494 } |
| 1488 | 1495 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1746 const char* termination_data[] = { | 1753 const char* termination_data[] = { |
| 1747 "", | 1754 "", |
| 1748 ";", | 1755 ";", |
| 1749 "\n", | 1756 "\n", |
| 1750 ";\n", | 1757 ";\n", |
| 1751 "\n;", | 1758 "\n;", |
| 1752 NULL | 1759 NULL |
| 1753 }; | 1760 }; |
| 1754 | 1761 |
| 1755 v8::HandleScope handles(CcTest::isolate()); | 1762 v8::HandleScope handles(CcTest::isolate()); |
| 1756 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1763 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1757 v8::Context::Scope context_scope(context); | 1764 v8::Context::Scope context_scope(context); |
| 1758 | 1765 |
| 1759 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1766 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 1760 i::GetCurrentStackPosition() - 128 * 1024); | 1767 i::GetCurrentStackPosition() - 128 * 1024); |
| 1761 | 1768 |
| 1762 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1769 for (int i = 0; context_data[i][0] != NULL; ++i) { |
| 1763 for (int j = 0; statement_data[j] != NULL; ++j) { | 1770 for (int j = 0; statement_data[j] != NULL; ++j) { |
| 1764 for (int k = 0; termination_data[k] != NULL; ++k) { | 1771 for (int k = 0; termination_data[k] != NULL; ++k) { |
| 1765 int kPrefixLen = i::StrLength(context_data[i][0]); | 1772 int kPrefixLen = i::StrLength(context_data[i][0]); |
| 1766 int kStatementLen = i::StrLength(statement_data[j]); | 1773 int kStatementLen = i::StrLength(statement_data[j]); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 v8::Context::Scope context_scope( | 1809 v8::Context::Scope context_scope( |
| 1803 v8::Context::New(CcTest::isolate())); | 1810 v8::Context::New(CcTest::isolate())); |
| 1804 v8::TryCatch try_catch(CcTest::isolate()); | 1811 v8::TryCatch try_catch(CcTest::isolate()); |
| 1805 const char* script = | 1812 const char* script = |
| 1806 "\"use strict\"; \n" | 1813 "\"use strict\"; \n" |
| 1807 "a = function() { \n" | 1814 "a = function() { \n" |
| 1808 " b = function() { \n" | 1815 " b = function() { \n" |
| 1809 " 01; \n" | 1816 " 01; \n" |
| 1810 " }; \n" | 1817 " }; \n" |
| 1811 "}; \n"; | 1818 "}; \n"; |
| 1812 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); | 1819 v8_compile(v8_str(script)); |
| 1813 CHECK(try_catch.HasCaught()); | 1820 CHECK(try_catch.HasCaught()); |
| 1814 v8::String::Utf8Value exception(try_catch.Exception()); | 1821 v8::String::Utf8Value exception(try_catch.Exception()); |
| 1815 CHECK_EQ(0, | 1822 CHECK_EQ(0, |
| 1816 strcmp("SyntaxError: Octal literals are not allowed in strict mode.", | 1823 strcmp("SyntaxError: Octal literals are not allowed in strict mode.", |
| 1817 *exception)); | 1824 *exception)); |
| 1818 } | 1825 } |
| 1819 | 1826 |
| 1820 | 1827 |
| 1821 void RunParserSyncTest(const char* context_data[][2], | 1828 void RunParserSyncTest(const char* context_data[][2], |
| 1822 const char* statement_data[], | 1829 const char* statement_data[], |
| 1823 ParserSyncTestResult result, | 1830 ParserSyncTestResult result, |
| 1824 const ParserFlag* flags = NULL, | 1831 const ParserFlag* flags = NULL, |
| 1825 int flags_len = 0, | 1832 int flags_len = 0, |
| 1826 const ParserFlag* always_true_flags = NULL, | 1833 const ParserFlag* always_true_flags = NULL, |
| 1827 int always_true_len = 0, | 1834 int always_true_len = 0, |
| 1828 const ParserFlag* always_false_flags = NULL, | 1835 const ParserFlag* always_false_flags = NULL, |
| 1829 int always_false_len = 0) { | 1836 int always_false_len = 0) { |
| 1830 v8::HandleScope handles(CcTest::isolate()); | 1837 v8::HandleScope handles(CcTest::isolate()); |
| 1831 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1838 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1832 v8::Context::Scope context_scope(context); | 1839 v8::Context::Scope context_scope(context); |
| 1833 | 1840 |
| 1834 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1841 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 1835 i::GetCurrentStackPosition() - 128 * 1024); | 1842 i::GetCurrentStackPosition() - 128 * 1024); |
| 1836 | 1843 |
| 1837 // Experimental feature flags should not go here; pass the flags as | 1844 // Experimental feature flags should not go here; pass the flags as |
| 1838 // always_true_flags if the test needs them. | 1845 // always_true_flags if the test needs them. |
| 1839 static const ParserFlag default_flags[] = { | 1846 static const ParserFlag default_flags[] = { |
| 1840 kAllowLazy, | 1847 kAllowLazy, |
| 1841 kAllowNatives, | 1848 kAllowNatives, |
| (...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3190 v8::Isolate* isolate = CcTest::isolate(); | 3197 v8::Isolate* isolate = CcTest::isolate(); |
| 3191 v8::HandleScope scope(isolate); | 3198 v8::HandleScope scope(isolate); |
| 3192 LocalContext env; | 3199 LocalContext env; |
| 3193 uint16_t* two_byte_source = AsciiToTwoByteString( | 3200 uint16_t* two_byte_source = AsciiToTwoByteString( |
| 3194 "var obj1 = { oXj2 : { foo1: function() {} } }; " | 3201 "var obj1 = { oXj2 : { foo1: function() {} } }; " |
| 3195 "%FunctionGetInferredName(obj1.oXj2.foo1)"); | 3202 "%FunctionGetInferredName(obj1.oXj2.foo1)"); |
| 3196 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); | 3203 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
| 3197 // Make it really non-Latin1 (replace the Xs with a non-Latin1 character). | 3204 // Make it really non-Latin1 (replace the Xs with a non-Latin1 character). |
| 3198 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; | 3205 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; |
| 3199 v8::Local<v8::String> source = | 3206 v8::Local<v8::String> source = |
| 3200 v8::String::NewFromTwoByte(isolate, two_byte_source); | 3207 v8::String::NewFromTwoByte(isolate, two_byte_source, |
| 3208 v8::NewStringType::kNormal) |
| 3209 .ToLocalChecked(); |
| 3201 v8::Local<v8::Value> result = CompileRun(source); | 3210 v8::Local<v8::Value> result = CompileRun(source); |
| 3202 CHECK(result->IsString()); | 3211 CHECK(result->IsString()); |
| 3203 v8::Local<v8::String> expected_name = | 3212 v8::Local<v8::String> expected_name = |
| 3204 v8::String::NewFromTwoByte(isolate, two_byte_name); | 3213 v8::String::NewFromTwoByte(isolate, two_byte_name, |
| 3205 CHECK(result->Equals(expected_name)); | 3214 v8::NewStringType::kNormal) |
| 3215 .ToLocalChecked(); |
| 3216 CHECK(result->Equals(isolate->GetCurrentContext(), expected_name).FromJust()); |
| 3206 i::DeleteArray(two_byte_source); | 3217 i::DeleteArray(two_byte_source); |
| 3207 i::DeleteArray(two_byte_name); | 3218 i::DeleteArray(two_byte_name); |
| 3208 } | 3219 } |
| 3209 | 3220 |
| 3210 | 3221 |
| 3211 TEST(FuncNameInferrerEscaped) { | 3222 TEST(FuncNameInferrerEscaped) { |
| 3212 // The same as FuncNameInferrerTwoByte, except that we express the two-byte | 3223 // The same as FuncNameInferrerTwoByte, except that we express the two-byte |
| 3213 // character as a unicode escape. | 3224 // character as a unicode escape. |
| 3214 i::FLAG_allow_natives_syntax = true; | 3225 i::FLAG_allow_natives_syntax = true; |
| 3215 v8::Isolate* isolate = CcTest::isolate(); | 3226 v8::Isolate* isolate = CcTest::isolate(); |
| 3216 v8::HandleScope scope(isolate); | 3227 v8::HandleScope scope(isolate); |
| 3217 LocalContext env; | 3228 LocalContext env; |
| 3218 uint16_t* two_byte_source = AsciiToTwoByteString( | 3229 uint16_t* two_byte_source = AsciiToTwoByteString( |
| 3219 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " | 3230 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " |
| 3220 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); | 3231 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); |
| 3221 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); | 3232 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
| 3222 // Fix to correspond to the non-ASCII name in two_byte_source. | 3233 // Fix to correspond to the non-ASCII name in two_byte_source. |
| 3223 two_byte_name[6] = 0x010d; | 3234 two_byte_name[6] = 0x010d; |
| 3224 v8::Local<v8::String> source = | 3235 v8::Local<v8::String> source = |
| 3225 v8::String::NewFromTwoByte(isolate, two_byte_source); | 3236 v8::String::NewFromTwoByte(isolate, two_byte_source, |
| 3237 v8::NewStringType::kNormal) |
| 3238 .ToLocalChecked(); |
| 3226 v8::Local<v8::Value> result = CompileRun(source); | 3239 v8::Local<v8::Value> result = CompileRun(source); |
| 3227 CHECK(result->IsString()); | 3240 CHECK(result->IsString()); |
| 3228 v8::Local<v8::String> expected_name = | 3241 v8::Local<v8::String> expected_name = |
| 3229 v8::String::NewFromTwoByte(isolate, two_byte_name); | 3242 v8::String::NewFromTwoByte(isolate, two_byte_name, |
| 3230 CHECK(result->Equals(expected_name)); | 3243 v8::NewStringType::kNormal) |
| 3244 .ToLocalChecked(); |
| 3245 CHECK(result->Equals(isolate->GetCurrentContext(), expected_name).FromJust()); |
| 3231 i::DeleteArray(two_byte_source); | 3246 i::DeleteArray(two_byte_source); |
| 3232 i::DeleteArray(two_byte_name); | 3247 i::DeleteArray(two_byte_name); |
| 3233 } | 3248 } |
| 3234 | 3249 |
| 3235 | 3250 |
| 3236 TEST(RegressionLazyFunctionWithErrorWithArg) { | 3251 TEST(RegressionLazyFunctionWithErrorWithArg) { |
| 3237 // The bug occurred when a lazy function had an error which requires a | 3252 // The bug occurred when a lazy function had an error which requires a |
| 3238 // parameter (such as "unknown label" here). The error message was processed | 3253 // parameter (such as "unknown label" here). The error message was processed |
| 3239 // before the AstValueFactory containing the error message string was | 3254 // before the AstValueFactory containing the error message string was |
| 3240 // internalized. | 3255 // internalized. |
| (...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5484 "import { for as f } from 'm.js';", | 5499 "import { for as f } from 'm.js';", |
| 5485 "import { yield as y } from 'm.js';", | 5500 "import { yield as y } from 'm.js';", |
| 5486 "import { static as s } from 'm.js';", | 5501 "import { static as s } from 'm.js';", |
| 5487 "import { let as l } from 'm.js';", | 5502 "import { let as l } from 'm.js';", |
| 5488 }; | 5503 }; |
| 5489 | 5504 |
| 5490 i::Isolate* isolate = CcTest::i_isolate(); | 5505 i::Isolate* isolate = CcTest::i_isolate(); |
| 5491 i::Factory* factory = isolate->factory(); | 5506 i::Factory* factory = isolate->factory(); |
| 5492 | 5507 |
| 5493 v8::HandleScope handles(CcTest::isolate()); | 5508 v8::HandleScope handles(CcTest::isolate()); |
| 5494 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5509 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5495 v8::Context::Scope context_scope(context); | 5510 v8::Context::Scope context_scope(context); |
| 5496 | 5511 |
| 5497 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5512 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5498 128 * 1024); | 5513 128 * 1024); |
| 5499 | 5514 |
| 5500 for (unsigned i = 0; i < arraysize(kSources); ++i) { | 5515 for (unsigned i = 0; i < arraysize(kSources); ++i) { |
| 5501 i::Handle<i::String> source = | 5516 i::Handle<i::String> source = |
| 5502 factory->NewStringFromAsciiChecked(kSources[i]); | 5517 factory->NewStringFromAsciiChecked(kSources[i]); |
| 5503 | 5518 |
| 5504 // Show that parsing as a module works | 5519 // Show that parsing as a module works |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5601 | 5616 |
| 5602 // TODO(ES6): These two forms should be supported | 5617 // TODO(ES6): These two forms should be supported |
| 5603 "export default function() {};", | 5618 "export default function() {};", |
| 5604 "export default class {};" | 5619 "export default class {};" |
| 5605 }; | 5620 }; |
| 5606 | 5621 |
| 5607 i::Isolate* isolate = CcTest::i_isolate(); | 5622 i::Isolate* isolate = CcTest::i_isolate(); |
| 5608 i::Factory* factory = isolate->factory(); | 5623 i::Factory* factory = isolate->factory(); |
| 5609 | 5624 |
| 5610 v8::HandleScope handles(CcTest::isolate()); | 5625 v8::HandleScope handles(CcTest::isolate()); |
| 5611 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5626 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5612 v8::Context::Scope context_scope(context); | 5627 v8::Context::Scope context_scope(context); |
| 5613 | 5628 |
| 5614 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5629 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5615 128 * 1024); | 5630 128 * 1024); |
| 5616 | 5631 |
| 5617 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 5632 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 5618 i::Handle<i::String> source = | 5633 i::Handle<i::String> source = |
| 5619 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 5634 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 5620 | 5635 |
| 5621 i::Handle<i::Script> script = factory->NewScript(source); | 5636 i::Handle<i::Script> script = factory->NewScript(source); |
| 5622 i::Zone zone; | 5637 i::Zone zone; |
| 5623 i::ParseInfo info(&zone, script); | 5638 i::ParseInfo info(&zone, script); |
| 5624 i::Parser parser(&info); | 5639 i::Parser parser(&info); |
| 5625 info.set_module(); | 5640 info.set_module(); |
| 5626 CHECK(!parser.Parse(&info)); | 5641 CHECK(!parser.Parse(&info)); |
| 5627 } | 5642 } |
| 5628 } | 5643 } |
| 5629 | 5644 |
| 5630 | 5645 |
| 5631 TEST(ModuleParsingInternals) { | 5646 TEST(ModuleParsingInternals) { |
| 5632 i::FLAG_harmony_modules = true; | 5647 i::FLAG_harmony_modules = true; |
| 5633 | 5648 |
| 5634 i::Isolate* isolate = CcTest::i_isolate(); | 5649 i::Isolate* isolate = CcTest::i_isolate(); |
| 5635 i::Factory* factory = isolate->factory(); | 5650 i::Factory* factory = isolate->factory(); |
| 5636 v8::HandleScope handles(CcTest::isolate()); | 5651 v8::HandleScope handles(CcTest::isolate()); |
| 5637 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5652 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5638 v8::Context::Scope context_scope(context); | 5653 v8::Context::Scope context_scope(context); |
| 5639 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5654 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5640 128 * 1024); | 5655 128 * 1024); |
| 5641 | 5656 |
| 5642 static const char kSource[] = | 5657 static const char kSource[] = |
| 5643 "let x = 5;" | 5658 "let x = 5;" |
| 5644 "export { x as y };" | 5659 "export { x as y };" |
| 5645 "import { q as z } from 'm.js';" | 5660 "import { q as z } from 'm.js';" |
| 5646 "import n from 'n.js';" | 5661 "import n from 'n.js';" |
| 5647 "export { a as b } from 'm.js';" | 5662 "export { a as b } from 'm.js';" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5759 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 5774 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 5760 always_flags, arraysize(always_flags)); | 5775 always_flags, arraysize(always_flags)); |
| 5761 } | 5776 } |
| 5762 | 5777 |
| 5763 | 5778 |
| 5764 void TestLanguageMode(const char* source, | 5779 void TestLanguageMode(const char* source, |
| 5765 i::LanguageMode expected_language_mode) { | 5780 i::LanguageMode expected_language_mode) { |
| 5766 i::Isolate* isolate = CcTest::i_isolate(); | 5781 i::Isolate* isolate = CcTest::i_isolate(); |
| 5767 i::Factory* factory = isolate->factory(); | 5782 i::Factory* factory = isolate->factory(); |
| 5768 v8::HandleScope handles(CcTest::isolate()); | 5783 v8::HandleScope handles(CcTest::isolate()); |
| 5769 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5784 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5770 v8::Context::Scope context_scope(context); | 5785 v8::Context::Scope context_scope(context); |
| 5771 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5786 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5772 128 * 1024); | 5787 128 * 1024); |
| 5773 | 5788 |
| 5774 i::Handle<i::Script> script = | 5789 i::Handle<i::Script> script = |
| 5775 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 5790 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
| 5776 i::Zone zone; | 5791 i::Zone zone; |
| 5777 i::ParseInfo info(&zone, script); | 5792 i::ParseInfo info(&zone, script); |
| 5778 i::Parser parser(&info); | 5793 i::Parser parser(&info); |
| 5779 parser.set_allow_strong_mode(true); | 5794 parser.set_allow_strong_mode(true); |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6447 CHECK(!try_catch.HasCaught()); | 6462 CHECK(!try_catch.HasCaught()); |
| 6448 | 6463 |
| 6449 // But not in strong mode. | 6464 // But not in strong mode. |
| 6450 { | 6465 { |
| 6451 const char* script2 = | 6466 const char* script2 = |
| 6452 "\"use strong\"; \n" | 6467 "\"use strong\"; \n" |
| 6453 "if (false) { \n" | 6468 "if (false) { \n" |
| 6454 " not_there2; \n" | 6469 " not_there2; \n" |
| 6455 "} \n"; | 6470 "} \n"; |
| 6456 v8::TryCatch try_catch2(CcTest::isolate()); | 6471 v8::TryCatch try_catch2(CcTest::isolate()); |
| 6457 v8::Script::Compile(v8_str(script2)); | 6472 v8_compile(v8_str(script2)); |
| 6458 CHECK(try_catch2.HasCaught()); | 6473 CHECK(try_catch2.HasCaught()); |
| 6459 v8::String::Utf8Value exception(try_catch2.Exception()); | 6474 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 6460 CHECK_EQ(0, | 6475 CHECK_EQ(0, |
| 6461 strcmp( | 6476 strcmp( |
| 6462 "ReferenceError: In strong mode, using an undeclared global " | 6477 "ReferenceError: In strong mode, using an undeclared global " |
| 6463 "variable 'not_there2' is not allowed", | 6478 "variable 'not_there2' is not allowed", |
| 6464 *exception)); | 6479 *exception)); |
| 6465 } | 6480 } |
| 6466 | 6481 |
| 6467 // Check that the variable reference is detected inside a strong function too, | 6482 // Check that the variable reference is detected inside a strong function too, |
| 6468 // even if the script scope is not strong. | 6483 // even if the script scope is not strong. |
| 6469 { | 6484 { |
| 6470 const char* script3 = | 6485 const char* script3 = |
| 6471 "(function not_lazy() { \n" | 6486 "(function not_lazy() { \n" |
| 6472 " \"use strong\"; \n" | 6487 " \"use strong\"; \n" |
| 6473 " if (false) { \n" | 6488 " if (false) { \n" |
| 6474 " not_there3; \n" | 6489 " not_there3; \n" |
| 6475 " } \n" | 6490 " } \n" |
| 6476 "})(); \n"; | 6491 "})(); \n"; |
| 6477 v8::TryCatch try_catch2(CcTest::isolate()); | 6492 v8::TryCatch try_catch2(CcTest::isolate()); |
| 6478 v8::Script::Compile(v8_str(script3)); | 6493 v8_compile(v8_str(script3)); |
| 6479 CHECK(try_catch2.HasCaught()); | 6494 CHECK(try_catch2.HasCaught()); |
| 6480 v8::String::Utf8Value exception(try_catch2.Exception()); | 6495 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 6481 CHECK_EQ(0, | 6496 CHECK_EQ(0, |
| 6482 strcmp( | 6497 strcmp( |
| 6483 "ReferenceError: In strong mode, using an undeclared global " | 6498 "ReferenceError: In strong mode, using an undeclared global " |
| 6484 "variable 'not_there3' is not allowed", | 6499 "variable 'not_there3' is not allowed", |
| 6485 *exception)); | 6500 *exception)); |
| 6486 } | 6501 } |
| 6487 } | 6502 } |
| 6488 | 6503 |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7221 NULL | 7236 NULL |
| 7222 }; | 7237 }; |
| 7223 // clang-format on | 7238 // clang-format on |
| 7224 | 7239 |
| 7225 static const ParserFlag fail_flags[] = { | 7240 static const ParserFlag fail_flags[] = { |
| 7226 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, | 7241 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, |
| 7227 kAllowHarmonyDestructuring}; | 7242 kAllowHarmonyDestructuring}; |
| 7228 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, | 7243 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, |
| 7229 arraysize(fail_flags)); | 7244 arraysize(fail_flags)); |
| 7230 } | 7245 } |
| OLD | NEW |