| 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_harmony_arrow_functions = true; | 235 i::FLAG_harmony_arrow_functions = true; |
| 231 i::FLAG_min_preparse_length = 0; | 236 i::FLAG_min_preparse_length = 0; |
| 232 v8::ScriptCompiler::Compile(isolate, &script_source, | 237 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source, |
| 233 v8::ScriptCompiler::kProduceParserCache); | 238 v8::ScriptCompiler::kProduceParserCache) |
| 239 .ToLocalChecked(); |
| 234 CHECK(script_source.GetCachedData()); | 240 CHECK(script_source.GetCachedData()); |
| 235 | 241 |
| 236 // Compile the script again, using the cached data. | 242 // Compile the script again, using the cached data. |
| 237 bool lazy_flag = i::FLAG_lazy; | 243 bool lazy_flag = i::FLAG_lazy; |
| 238 i::FLAG_lazy = true; | 244 i::FLAG_lazy = true; |
| 239 v8::ScriptCompiler::Compile(isolate, &script_source, | 245 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source, |
| 240 v8::ScriptCompiler::kConsumeParserCache); | 246 v8::ScriptCompiler::kConsumeParserCache) |
| 247 .ToLocalChecked(); |
| 241 i::FLAG_lazy = false; | 248 i::FLAG_lazy = false; |
| 242 v8::ScriptCompiler::CompileUnbound(isolate, &script_source, | 249 v8::ScriptCompiler::CompileUnboundScript( |
| 243 v8::ScriptCompiler::kConsumeParserCache); | 250 isolate, &script_source, v8::ScriptCompiler::kConsumeParserCache) |
| 251 .ToLocalChecked(); |
| 244 i::FLAG_lazy = lazy_flag; | 252 i::FLAG_lazy = lazy_flag; |
| 245 } | 253 } |
| 246 | 254 |
| 247 | 255 |
| 248 TEST(PreparseFunctionDataIsUsed) { | 256 TEST(PreparseFunctionDataIsUsed) { |
| 249 // This tests that we actually do use the function data generated by the | 257 // This tests that we actually do use the function data generated by the |
| 250 // preparser. | 258 // preparser. |
| 251 | 259 |
| 252 // Make preparsing work for short scripts. | 260 // Make preparsing work for short scripts. |
| 253 i::FLAG_min_preparse_length = 0; | 261 i::FLAG_min_preparse_length = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 266 }; | 274 }; |
| 267 | 275 |
| 268 // Insert a syntax error inside the lazy function. | 276 // Insert a syntax error inside the lazy function. |
| 269 const char* bad_code[] = { | 277 const char* bad_code[] = { |
| 270 "function this_is_lazy() { if ( } function foo() { return 25; } foo();", | 278 "function this_is_lazy() { if ( } function foo() { return 25; } foo();", |
| 271 "var this_is_lazy = () => { if ( }; var foo = () => 25; foo();", | 279 "var this_is_lazy = () => { if ( }; var foo = () => 25; foo();", |
| 272 }; | 280 }; |
| 273 | 281 |
| 274 for (unsigned i = 0; i < arraysize(good_code); i++) { | 282 for (unsigned i = 0; i < arraysize(good_code); i++) { |
| 275 v8::ScriptCompiler::Source good_source(v8_str(good_code[i])); | 283 v8::ScriptCompiler::Source good_source(v8_str(good_code[i])); |
| 276 v8::ScriptCompiler::Compile(isolate, &good_source, | 284 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &good_source, |
| 277 v8::ScriptCompiler::kProduceParserCache); | 285 v8::ScriptCompiler::kProduceParserCache) |
| 286 .ToLocalChecked(); |
| 278 | 287 |
| 279 const v8::ScriptCompiler::CachedData* cached_data = | 288 const v8::ScriptCompiler::CachedData* cached_data = |
| 280 good_source.GetCachedData(); | 289 good_source.GetCachedData(); |
| 281 CHECK(cached_data->data != NULL); | 290 CHECK(cached_data->data != NULL); |
| 282 CHECK_GT(cached_data->length, 0); | 291 CHECK_GT(cached_data->length, 0); |
| 283 | 292 |
| 284 // Now compile the erroneous code with the good preparse data. If the | 293 // Now compile the erroneous code with the good preparse data. If the |
| 285 // preparse data is used, the lazy function is skipped and it should | 294 // preparse data is used, the lazy function is skipped and it should |
| 286 // compile fine. | 295 // compile fine. |
| 287 v8::ScriptCompiler::Source bad_source( | 296 v8::ScriptCompiler::Source bad_source( |
| 288 v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData( | 297 v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData( |
| 289 cached_data->data, cached_data->length)); | 298 cached_data->data, cached_data->length)); |
| 290 v8::Local<v8::Value> result = | 299 v8::Local<v8::Value> result = |
| 291 v8::ScriptCompiler::Compile(isolate, &bad_source, | 300 CompileRun(isolate->GetCurrentContext(), &bad_source, |
| 292 v8::ScriptCompiler::kConsumeParserCache) | 301 v8::ScriptCompiler::kConsumeParserCache); |
| 293 ->Run(); | |
| 294 CHECK(result->IsInt32()); | 302 CHECK(result->IsInt32()); |
| 295 CHECK_EQ(25, result->Int32Value()); | 303 CHECK_EQ(25, result->Int32Value(isolate->GetCurrentContext()).FromJust()); |
| 296 } | 304 } |
| 297 } | 305 } |
| 298 | 306 |
| 299 | 307 |
| 300 TEST(StandAlonePreParser) { | 308 TEST(StandAlonePreParser) { |
| 301 v8::V8::Initialize(); | 309 v8::V8::Initialize(); |
| 302 | 310 |
| 303 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 311 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 304 i::GetCurrentStackPosition() - 128 * 1024); | 312 i::GetCurrentStackPosition() - 128 * 1024); |
| 305 | 313 |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 {"eval('super.x')", EVAL}, | 1039 {"eval('super.x')", EVAL}, |
| 1032 {"eval('this.x')", EVAL}, | 1040 {"eval('this.x')", EVAL}, |
| 1033 {"eval('arguments')", EVAL}, | 1041 {"eval('arguments')", EVAL}, |
| 1034 }; | 1042 }; |
| 1035 // clang-format on | 1043 // clang-format on |
| 1036 | 1044 |
| 1037 i::Isolate* isolate = CcTest::i_isolate(); | 1045 i::Isolate* isolate = CcTest::i_isolate(); |
| 1038 i::Factory* factory = isolate->factory(); | 1046 i::Factory* factory = isolate->factory(); |
| 1039 | 1047 |
| 1040 v8::HandleScope handles(CcTest::isolate()); | 1048 v8::HandleScope handles(CcTest::isolate()); |
| 1041 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1049 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1042 v8::Context::Scope context_scope(context); | 1050 v8::Context::Scope context_scope(context); |
| 1043 | 1051 |
| 1044 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 1052 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 1045 128 * 1024); | 1053 128 * 1024); |
| 1046 | 1054 |
| 1047 for (unsigned j = 0; j < arraysize(surroundings); ++j) { | 1055 for (unsigned j = 0; j < arraysize(surroundings); ++j) { |
| 1048 for (unsigned i = 0; i < arraysize(source_data); ++i) { | 1056 for (unsigned i = 0; i < arraysize(source_data); ++i) { |
| 1049 // Super property is only allowed in constructor and method. | 1057 // Super property is only allowed in constructor and method. |
| 1050 if (((source_data[i].expected & SUPER_PROPERTY) || | 1058 if (((source_data[i].expected & SUPER_PROPERTY) || |
| 1051 (source_data[i].expected == NONE)) && j != 2) { | 1059 (source_data[i].expected == NONE)) && j != 2) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 { " 'foo';\n" | 1346 { " 'foo';\n" |
| 1339 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", | 1347 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", |
| 1340 i::FUNCTION_SCOPE, i::SLOPPY }, | 1348 i::FUNCTION_SCOPE, i::SLOPPY }, |
| 1341 { NULL, NULL, NULL, i::EVAL_SCOPE, i::SLOPPY } | 1349 { NULL, NULL, NULL, i::EVAL_SCOPE, i::SLOPPY } |
| 1342 }; | 1350 }; |
| 1343 | 1351 |
| 1344 i::Isolate* isolate = CcTest::i_isolate(); | 1352 i::Isolate* isolate = CcTest::i_isolate(); |
| 1345 i::Factory* factory = isolate->factory(); | 1353 i::Factory* factory = isolate->factory(); |
| 1346 | 1354 |
| 1347 v8::HandleScope handles(CcTest::isolate()); | 1355 v8::HandleScope handles(CcTest::isolate()); |
| 1348 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1356 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1349 v8::Context::Scope context_scope(context); | 1357 v8::Context::Scope context_scope(context); |
| 1350 | 1358 |
| 1351 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 1359 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 1352 128 * 1024); | 1360 128 * 1024); |
| 1353 | 1361 |
| 1354 for (int i = 0; source_data[i].outer_prefix; i++) { | 1362 for (int i = 0; source_data[i].outer_prefix; i++) { |
| 1355 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); | 1363 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); |
| 1356 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); | 1364 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); |
| 1357 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); | 1365 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); |
| 1358 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); | 1366 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 i::Handle<i::String> FormatMessage(i::Vector<unsigned> data) { | 1482 i::Handle<i::String> FormatMessage(i::Vector<unsigned> data) { |
| 1475 i::Isolate* isolate = CcTest::i_isolate(); | 1483 i::Isolate* isolate = CcTest::i_isolate(); |
| 1476 int message = data[i::PreparseDataConstants::kMessageTemplatePos]; | 1484 int message = data[i::PreparseDataConstants::kMessageTemplatePos]; |
| 1477 int arg_count = data[i::PreparseDataConstants::kMessageArgCountPos]; | 1485 int arg_count = data[i::PreparseDataConstants::kMessageArgCountPos]; |
| 1478 i::Handle<i::Object> arg_object; | 1486 i::Handle<i::Object> arg_object; |
| 1479 if (arg_count == 1) { | 1487 if (arg_count == 1) { |
| 1480 // Position after text found by skipping past length field and | 1488 // Position after text found by skipping past length field and |
| 1481 // length field content words. | 1489 // length field content words. |
| 1482 const char* arg = | 1490 const char* arg = |
| 1483 ReadString(&data[i::PreparseDataConstants::kMessageArgPos]); | 1491 ReadString(&data[i::PreparseDataConstants::kMessageArgPos]); |
| 1484 arg_object = | 1492 arg_object = v8::Utils::OpenHandle(*v8_str(arg)); |
| 1485 v8::Utils::OpenHandle(*v8::String::NewFromUtf8(CcTest::isolate(), arg)); | |
| 1486 i::DeleteArray(arg); | 1493 i::DeleteArray(arg); |
| 1487 } else { | 1494 } else { |
| 1488 CHECK_EQ(0, arg_count); | 1495 CHECK_EQ(0, arg_count); |
| 1489 arg_object = isolate->factory()->undefined_value(); | 1496 arg_object = isolate->factory()->undefined_value(); |
| 1490 } | 1497 } |
| 1491 | 1498 |
| 1492 data.Dispose(); | 1499 data.Dispose(); |
| 1493 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1500 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
| 1494 } | 1501 } |
| 1495 | 1502 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 const char* termination_data[] = { | 1763 const char* termination_data[] = { |
| 1757 "", | 1764 "", |
| 1758 ";", | 1765 ";", |
| 1759 "\n", | 1766 "\n", |
| 1760 ";\n", | 1767 ";\n", |
| 1761 "\n;", | 1768 "\n;", |
| 1762 NULL | 1769 NULL |
| 1763 }; | 1770 }; |
| 1764 | 1771 |
| 1765 v8::HandleScope handles(CcTest::isolate()); | 1772 v8::HandleScope handles(CcTest::isolate()); |
| 1766 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1773 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1767 v8::Context::Scope context_scope(context); | 1774 v8::Context::Scope context_scope(context); |
| 1768 | 1775 |
| 1769 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1776 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 1770 i::GetCurrentStackPosition() - 128 * 1024); | 1777 i::GetCurrentStackPosition() - 128 * 1024); |
| 1771 | 1778 |
| 1772 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1779 for (int i = 0; context_data[i][0] != NULL; ++i) { |
| 1773 for (int j = 0; statement_data[j] != NULL; ++j) { | 1780 for (int j = 0; statement_data[j] != NULL; ++j) { |
| 1774 for (int k = 0; termination_data[k] != NULL; ++k) { | 1781 for (int k = 0; termination_data[k] != NULL; ++k) { |
| 1775 int kPrefixLen = i::StrLength(context_data[i][0]); | 1782 int kPrefixLen = i::StrLength(context_data[i][0]); |
| 1776 int kStatementLen = i::StrLength(statement_data[j]); | 1783 int kStatementLen = i::StrLength(statement_data[j]); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 v8::Context::Scope context_scope( | 1819 v8::Context::Scope context_scope( |
| 1813 v8::Context::New(CcTest::isolate())); | 1820 v8::Context::New(CcTest::isolate())); |
| 1814 v8::TryCatch try_catch(CcTest::isolate()); | 1821 v8::TryCatch try_catch(CcTest::isolate()); |
| 1815 const char* script = | 1822 const char* script = |
| 1816 "\"use strict\"; \n" | 1823 "\"use strict\"; \n" |
| 1817 "a = function() { \n" | 1824 "a = function() { \n" |
| 1818 " b = function() { \n" | 1825 " b = function() { \n" |
| 1819 " 01; \n" | 1826 " 01; \n" |
| 1820 " }; \n" | 1827 " }; \n" |
| 1821 "}; \n"; | 1828 "}; \n"; |
| 1822 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); | 1829 v8_compile(v8_str(script)); |
| 1823 CHECK(try_catch.HasCaught()); | 1830 CHECK(try_catch.HasCaught()); |
| 1824 v8::String::Utf8Value exception(try_catch.Exception()); | 1831 v8::String::Utf8Value exception(try_catch.Exception()); |
| 1825 CHECK_EQ(0, | 1832 CHECK_EQ(0, |
| 1826 strcmp("SyntaxError: Octal literals are not allowed in strict mode.", | 1833 strcmp("SyntaxError: Octal literals are not allowed in strict mode.", |
| 1827 *exception)); | 1834 *exception)); |
| 1828 } | 1835 } |
| 1829 | 1836 |
| 1830 | 1837 |
| 1831 void RunParserSyncTest(const char* context_data[][2], | 1838 void RunParserSyncTest(const char* context_data[][2], |
| 1832 const char* statement_data[], | 1839 const char* statement_data[], |
| 1833 ParserSyncTestResult result, | 1840 ParserSyncTestResult result, |
| 1834 const ParserFlag* flags = NULL, | 1841 const ParserFlag* flags = NULL, |
| 1835 int flags_len = 0, | 1842 int flags_len = 0, |
| 1836 const ParserFlag* always_true_flags = NULL, | 1843 const ParserFlag* always_true_flags = NULL, |
| 1837 int always_true_len = 0, | 1844 int always_true_len = 0, |
| 1838 const ParserFlag* always_false_flags = NULL, | 1845 const ParserFlag* always_false_flags = NULL, |
| 1839 int always_false_len = 0) { | 1846 int always_false_len = 0) { |
| 1840 v8::HandleScope handles(CcTest::isolate()); | 1847 v8::HandleScope handles(CcTest::isolate()); |
| 1841 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1848 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1842 v8::Context::Scope context_scope(context); | 1849 v8::Context::Scope context_scope(context); |
| 1843 | 1850 |
| 1844 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1851 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 1845 i::GetCurrentStackPosition() - 128 * 1024); | 1852 i::GetCurrentStackPosition() - 128 * 1024); |
| 1846 | 1853 |
| 1847 // Experimental feature flags should not go here; pass the flags as | 1854 // Experimental feature flags should not go here; pass the flags as |
| 1848 // always_true_flags if the test needs them. | 1855 // always_true_flags if the test needs them. |
| 1849 static const ParserFlag default_flags[] = { | 1856 static const ParserFlag default_flags[] = { |
| 1850 kAllowLazy, | 1857 kAllowLazy, |
| 1851 kAllowNatives, | 1858 kAllowNatives, |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3212 v8::Isolate* isolate = CcTest::isolate(); | 3219 v8::Isolate* isolate = CcTest::isolate(); |
| 3213 v8::HandleScope scope(isolate); | 3220 v8::HandleScope scope(isolate); |
| 3214 LocalContext env; | 3221 LocalContext env; |
| 3215 uint16_t* two_byte_source = AsciiToTwoByteString( | 3222 uint16_t* two_byte_source = AsciiToTwoByteString( |
| 3216 "var obj1 = { oXj2 : { foo1: function() {} } }; " | 3223 "var obj1 = { oXj2 : { foo1: function() {} } }; " |
| 3217 "%FunctionGetInferredName(obj1.oXj2.foo1)"); | 3224 "%FunctionGetInferredName(obj1.oXj2.foo1)"); |
| 3218 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); | 3225 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
| 3219 // Make it really non-Latin1 (replace the Xs with a non-Latin1 character). | 3226 // Make it really non-Latin1 (replace the Xs with a non-Latin1 character). |
| 3220 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; | 3227 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; |
| 3221 v8::Local<v8::String> source = | 3228 v8::Local<v8::String> source = |
| 3222 v8::String::NewFromTwoByte(isolate, two_byte_source); | 3229 v8::String::NewFromTwoByte(isolate, two_byte_source, |
| 3230 v8::NewStringType::kNormal) |
| 3231 .ToLocalChecked(); |
| 3223 v8::Local<v8::Value> result = CompileRun(source); | 3232 v8::Local<v8::Value> result = CompileRun(source); |
| 3224 CHECK(result->IsString()); | 3233 CHECK(result->IsString()); |
| 3225 v8::Local<v8::String> expected_name = | 3234 v8::Local<v8::String> expected_name = |
| 3226 v8::String::NewFromTwoByte(isolate, two_byte_name); | 3235 v8::String::NewFromTwoByte(isolate, two_byte_name, |
| 3227 CHECK(result->Equals(expected_name)); | 3236 v8::NewStringType::kNormal) |
| 3237 .ToLocalChecked(); |
| 3238 CHECK(result->Equals(isolate->GetCurrentContext(), expected_name).FromJust()); |
| 3228 i::DeleteArray(two_byte_source); | 3239 i::DeleteArray(two_byte_source); |
| 3229 i::DeleteArray(two_byte_name); | 3240 i::DeleteArray(two_byte_name); |
| 3230 } | 3241 } |
| 3231 | 3242 |
| 3232 | 3243 |
| 3233 TEST(FuncNameInferrerEscaped) { | 3244 TEST(FuncNameInferrerEscaped) { |
| 3234 // The same as FuncNameInferrerTwoByte, except that we express the two-byte | 3245 // The same as FuncNameInferrerTwoByte, except that we express the two-byte |
| 3235 // character as a unicode escape. | 3246 // character as a unicode escape. |
| 3236 i::FLAG_allow_natives_syntax = true; | 3247 i::FLAG_allow_natives_syntax = true; |
| 3237 v8::Isolate* isolate = CcTest::isolate(); | 3248 v8::Isolate* isolate = CcTest::isolate(); |
| 3238 v8::HandleScope scope(isolate); | 3249 v8::HandleScope scope(isolate); |
| 3239 LocalContext env; | 3250 LocalContext env; |
| 3240 uint16_t* two_byte_source = AsciiToTwoByteString( | 3251 uint16_t* two_byte_source = AsciiToTwoByteString( |
| 3241 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " | 3252 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " |
| 3242 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); | 3253 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); |
| 3243 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); | 3254 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
| 3244 // Fix to correspond to the non-ASCII name in two_byte_source. | 3255 // Fix to correspond to the non-ASCII name in two_byte_source. |
| 3245 two_byte_name[6] = 0x010d; | 3256 two_byte_name[6] = 0x010d; |
| 3246 v8::Local<v8::String> source = | 3257 v8::Local<v8::String> source = |
| 3247 v8::String::NewFromTwoByte(isolate, two_byte_source); | 3258 v8::String::NewFromTwoByte(isolate, two_byte_source, |
| 3259 v8::NewStringType::kNormal) |
| 3260 .ToLocalChecked(); |
| 3248 v8::Local<v8::Value> result = CompileRun(source); | 3261 v8::Local<v8::Value> result = CompileRun(source); |
| 3249 CHECK(result->IsString()); | 3262 CHECK(result->IsString()); |
| 3250 v8::Local<v8::String> expected_name = | 3263 v8::Local<v8::String> expected_name = |
| 3251 v8::String::NewFromTwoByte(isolate, two_byte_name); | 3264 v8::String::NewFromTwoByte(isolate, two_byte_name, |
| 3252 CHECK(result->Equals(expected_name)); | 3265 v8::NewStringType::kNormal) |
| 3266 .ToLocalChecked(); |
| 3267 CHECK(result->Equals(isolate->GetCurrentContext(), expected_name).FromJust()); |
| 3253 i::DeleteArray(two_byte_source); | 3268 i::DeleteArray(two_byte_source); |
| 3254 i::DeleteArray(two_byte_name); | 3269 i::DeleteArray(two_byte_name); |
| 3255 } | 3270 } |
| 3256 | 3271 |
| 3257 | 3272 |
| 3258 TEST(RegressionLazyFunctionWithErrorWithArg) { | 3273 TEST(RegressionLazyFunctionWithErrorWithArg) { |
| 3259 // The bug occurred when a lazy function had an error which requires a | 3274 // The bug occurred when a lazy function had an error which requires a |
| 3260 // parameter (such as "unknown label" here). The error message was processed | 3275 // parameter (such as "unknown label" here). The error message was processed |
| 3261 // before the AstValueFactory containing the error message string was | 3276 // before the AstValueFactory containing the error message string was |
| 3262 // internalized. | 3277 // internalized. |
| (...skipping 2251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5514 "import { for as f } from 'm.js';", | 5529 "import { for as f } from 'm.js';", |
| 5515 "import { yield as y } from 'm.js';", | 5530 "import { yield as y } from 'm.js';", |
| 5516 "import { static as s } from 'm.js';", | 5531 "import { static as s } from 'm.js';", |
| 5517 "import { let as l } from 'm.js';", | 5532 "import { let as l } from 'm.js';", |
| 5518 }; | 5533 }; |
| 5519 | 5534 |
| 5520 i::Isolate* isolate = CcTest::i_isolate(); | 5535 i::Isolate* isolate = CcTest::i_isolate(); |
| 5521 i::Factory* factory = isolate->factory(); | 5536 i::Factory* factory = isolate->factory(); |
| 5522 | 5537 |
| 5523 v8::HandleScope handles(CcTest::isolate()); | 5538 v8::HandleScope handles(CcTest::isolate()); |
| 5524 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5539 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5525 v8::Context::Scope context_scope(context); | 5540 v8::Context::Scope context_scope(context); |
| 5526 | 5541 |
| 5527 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5542 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5528 128 * 1024); | 5543 128 * 1024); |
| 5529 | 5544 |
| 5530 for (unsigned i = 0; i < arraysize(kSources); ++i) { | 5545 for (unsigned i = 0; i < arraysize(kSources); ++i) { |
| 5531 i::Handle<i::String> source = | 5546 i::Handle<i::String> source = |
| 5532 factory->NewStringFromAsciiChecked(kSources[i]); | 5547 factory->NewStringFromAsciiChecked(kSources[i]); |
| 5533 | 5548 |
| 5534 // Show that parsing as a module works | 5549 // Show that parsing as a module works |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5631 | 5646 |
| 5632 // TODO(ES6): These two forms should be supported | 5647 // TODO(ES6): These two forms should be supported |
| 5633 "export default function() {};", | 5648 "export default function() {};", |
| 5634 "export default class {};" | 5649 "export default class {};" |
| 5635 }; | 5650 }; |
| 5636 | 5651 |
| 5637 i::Isolate* isolate = CcTest::i_isolate(); | 5652 i::Isolate* isolate = CcTest::i_isolate(); |
| 5638 i::Factory* factory = isolate->factory(); | 5653 i::Factory* factory = isolate->factory(); |
| 5639 | 5654 |
| 5640 v8::HandleScope handles(CcTest::isolate()); | 5655 v8::HandleScope handles(CcTest::isolate()); |
| 5641 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5656 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5642 v8::Context::Scope context_scope(context); | 5657 v8::Context::Scope context_scope(context); |
| 5643 | 5658 |
| 5644 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5659 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5645 128 * 1024); | 5660 128 * 1024); |
| 5646 | 5661 |
| 5647 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 5662 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 5648 i::Handle<i::String> source = | 5663 i::Handle<i::String> source = |
| 5649 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 5664 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 5650 | 5665 |
| 5651 i::Handle<i::Script> script = factory->NewScript(source); | 5666 i::Handle<i::Script> script = factory->NewScript(source); |
| 5652 i::Zone zone; | 5667 i::Zone zone; |
| 5653 i::ParseInfo info(&zone, script); | 5668 i::ParseInfo info(&zone, script); |
| 5654 i::Parser parser(&info); | 5669 i::Parser parser(&info); |
| 5655 info.set_module(); | 5670 info.set_module(); |
| 5656 CHECK(!parser.Parse(&info)); | 5671 CHECK(!parser.Parse(&info)); |
| 5657 } | 5672 } |
| 5658 } | 5673 } |
| 5659 | 5674 |
| 5660 | 5675 |
| 5661 TEST(ModuleParsingInternals) { | 5676 TEST(ModuleParsingInternals) { |
| 5662 i::FLAG_harmony_modules = true; | 5677 i::FLAG_harmony_modules = true; |
| 5663 | 5678 |
| 5664 i::Isolate* isolate = CcTest::i_isolate(); | 5679 i::Isolate* isolate = CcTest::i_isolate(); |
| 5665 i::Factory* factory = isolate->factory(); | 5680 i::Factory* factory = isolate->factory(); |
| 5666 v8::HandleScope handles(CcTest::isolate()); | 5681 v8::HandleScope handles(CcTest::isolate()); |
| 5667 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5682 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5668 v8::Context::Scope context_scope(context); | 5683 v8::Context::Scope context_scope(context); |
| 5669 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5684 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5670 128 * 1024); | 5685 128 * 1024); |
| 5671 | 5686 |
| 5672 static const char kSource[] = | 5687 static const char kSource[] = |
| 5673 "let x = 5;" | 5688 "let x = 5;" |
| 5674 "export { x as y };" | 5689 "export { x as y };" |
| 5675 "import { q as z } from 'm.js';" | 5690 "import { q as z } from 'm.js';" |
| 5676 "import n from 'n.js';" | 5691 "import n from 'n.js';" |
| 5677 "export { a as b } from 'm.js';" | 5692 "export { a as b } from 'm.js';" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5789 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 5804 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 5790 always_flags, arraysize(always_flags)); | 5805 always_flags, arraysize(always_flags)); |
| 5791 } | 5806 } |
| 5792 | 5807 |
| 5793 | 5808 |
| 5794 void TestLanguageMode(const char* source, | 5809 void TestLanguageMode(const char* source, |
| 5795 i::LanguageMode expected_language_mode) { | 5810 i::LanguageMode expected_language_mode) { |
| 5796 i::Isolate* isolate = CcTest::i_isolate(); | 5811 i::Isolate* isolate = CcTest::i_isolate(); |
| 5797 i::Factory* factory = isolate->factory(); | 5812 i::Factory* factory = isolate->factory(); |
| 5798 v8::HandleScope handles(CcTest::isolate()); | 5813 v8::HandleScope handles(CcTest::isolate()); |
| 5799 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5814 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5800 v8::Context::Scope context_scope(context); | 5815 v8::Context::Scope context_scope(context); |
| 5801 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5816 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5802 128 * 1024); | 5817 128 * 1024); |
| 5803 | 5818 |
| 5804 i::Handle<i::Script> script = | 5819 i::Handle<i::Script> script = |
| 5805 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 5820 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
| 5806 i::Zone zone; | 5821 i::Zone zone; |
| 5807 i::ParseInfo info(&zone, script); | 5822 i::ParseInfo info(&zone, script); |
| 5808 i::Parser parser(&info); | 5823 i::Parser parser(&info); |
| 5809 parser.set_allow_strong_mode(true); | 5824 parser.set_allow_strong_mode(true); |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6483 CHECK(!try_catch.HasCaught()); | 6498 CHECK(!try_catch.HasCaught()); |
| 6484 | 6499 |
| 6485 // But not in strong mode. | 6500 // But not in strong mode. |
| 6486 { | 6501 { |
| 6487 const char* script2 = | 6502 const char* script2 = |
| 6488 "\"use strong\"; \n" | 6503 "\"use strong\"; \n" |
| 6489 "if (false) { \n" | 6504 "if (false) { \n" |
| 6490 " not_there2; \n" | 6505 " not_there2; \n" |
| 6491 "} \n"; | 6506 "} \n"; |
| 6492 v8::TryCatch try_catch2(CcTest::isolate()); | 6507 v8::TryCatch try_catch2(CcTest::isolate()); |
| 6493 v8::Script::Compile(v8_str(script2)); | 6508 v8_compile(v8_str(script2)); |
| 6494 CHECK(try_catch2.HasCaught()); | 6509 CHECK(try_catch2.HasCaught()); |
| 6495 v8::String::Utf8Value exception(try_catch2.Exception()); | 6510 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 6496 CHECK_EQ(0, | 6511 CHECK_EQ(0, |
| 6497 strcmp( | 6512 strcmp( |
| 6498 "ReferenceError: In strong mode, using an undeclared global " | 6513 "ReferenceError: In strong mode, using an undeclared global " |
| 6499 "variable 'not_there2' is not allowed", | 6514 "variable 'not_there2' is not allowed", |
| 6500 *exception)); | 6515 *exception)); |
| 6501 } | 6516 } |
| 6502 | 6517 |
| 6503 // Check that the variable reference is detected inside a strong function too, | 6518 // Check that the variable reference is detected inside a strong function too, |
| 6504 // even if the script scope is not strong. | 6519 // even if the script scope is not strong. |
| 6505 { | 6520 { |
| 6506 const char* script3 = | 6521 const char* script3 = |
| 6507 "(function not_lazy() { \n" | 6522 "(function not_lazy() { \n" |
| 6508 " \"use strong\"; \n" | 6523 " \"use strong\"; \n" |
| 6509 " if (false) { \n" | 6524 " if (false) { \n" |
| 6510 " not_there3; \n" | 6525 " not_there3; \n" |
| 6511 " } \n" | 6526 " } \n" |
| 6512 "})(); \n"; | 6527 "})(); \n"; |
| 6513 v8::TryCatch try_catch2(CcTest::isolate()); | 6528 v8::TryCatch try_catch2(CcTest::isolate()); |
| 6514 v8::Script::Compile(v8_str(script3)); | 6529 v8_compile(v8_str(script3)); |
| 6515 CHECK(try_catch2.HasCaught()); | 6530 CHECK(try_catch2.HasCaught()); |
| 6516 v8::String::Utf8Value exception(try_catch2.Exception()); | 6531 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 6517 CHECK_EQ(0, | 6532 CHECK_EQ(0, |
| 6518 strcmp( | 6533 strcmp( |
| 6519 "ReferenceError: In strong mode, using an undeclared global " | 6534 "ReferenceError: In strong mode, using an undeclared global " |
| 6520 "variable 'not_there3' is not allowed", | 6535 "variable 'not_there3' is not allowed", |
| 6521 *exception)); | 6536 *exception)); |
| 6522 } | 6537 } |
| 6523 } | 6538 } |
| 6524 | 6539 |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7231 "for (let in {}) {}", | 7246 "for (let in {}) {}", |
| 7232 NULL | 7247 NULL |
| 7233 }; | 7248 }; |
| 7234 // clang-format on | 7249 // clang-format on |
| 7235 | 7250 |
| 7236 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 7251 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
| 7237 kAllowHarmonySloppyLet}; | 7252 kAllowHarmonySloppyLet}; |
| 7238 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 7253 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 7239 arraysize(always_flags)); | 7254 arraysize(always_flags)); |
| 7240 } | 7255 } |
| OLD | NEW |