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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 i::PreParser preparser(&scanner, &log, stack_limit); | 172 i::PreParser preparser(&scanner, &log, stack_limit); |
173 preparser.set_allow_lazy(true); | 173 preparser.set_allow_lazy(true); |
174 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 174 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
175 // Even in the case of a syntax error, kPreParseSuccess is returned. | 175 // Even in the case of a syntax error, kPreParseSuccess is returned. |
176 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 176 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
177 CHECK(log.HasError()); | 177 CHECK(log.HasError()); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 class ScriptResource : public v8::String::ExternalAsciiStringResource { | 182 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
183 public: | 183 public: |
184 ScriptResource(const char* data, size_t length) | 184 ScriptResource(const char* data, size_t length) |
185 : data_(data), length_(length) { } | 185 : data_(data), length_(length) { } |
186 | 186 |
187 const char* data() const { return data_; } | 187 const char* data() const { return data_; } |
188 size_t length() const { return length_; } | 188 size_t length() const { return length_; } |
189 | 189 |
190 private: | 190 private: |
191 const char* data_; | 191 const char* data_; |
192 size_t length_; | 192 size_t length_; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 return length_; | 517 return length_; |
518 } | 518 } |
519 private: | 519 private: |
520 uint16_t* data_; | 520 uint16_t* data_; |
521 size_t length_; | 521 size_t length_; |
522 }; | 522 }; |
523 | 523 |
524 | 524 |
525 #define CHECK_EQU(v1, v2) CHECK_EQ(static_cast<int>(v1), static_cast<int>(v2)) | 525 #define CHECK_EQU(v1, v2) CHECK_EQ(static_cast<int>(v1), static_cast<int>(v2)) |
526 | 526 |
527 void TestCharacterStream(const char* ascii_source, | 527 void TestCharacterStream(const char* one_byte_source, unsigned length, |
528 unsigned length, | 528 unsigned start = 0, unsigned end = 0) { |
529 unsigned start = 0, | |
530 unsigned end = 0) { | |
531 if (end == 0) end = length; | 529 if (end == 0) end = length; |
532 unsigned sub_length = end - start; | 530 unsigned sub_length = end - start; |
533 i::Isolate* isolate = CcTest::i_isolate(); | 531 i::Isolate* isolate = CcTest::i_isolate(); |
534 i::Factory* factory = isolate->factory(); | 532 i::Factory* factory = isolate->factory(); |
535 i::HandleScope test_scope(isolate); | 533 i::HandleScope test_scope(isolate); |
536 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); | 534 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); |
537 for (unsigned i = 0; i < length; i++) { | 535 for (unsigned i = 0; i < length; i++) { |
538 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); | 536 uc16_buffer[i] = static_cast<i::uc16>(one_byte_source[i]); |
539 } | 537 } |
540 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); | 538 i::Vector<const char> one_byte_vector(one_byte_source, |
541 i::Handle<i::String> ascii_string = | 539 static_cast<int>(length)); |
542 factory->NewStringFromAscii(ascii_vector).ToHandleChecked(); | 540 i::Handle<i::String> one_byte_string = |
| 541 factory->NewStringFromAscii(one_byte_vector).ToHandleChecked(); |
543 TestExternalResource resource(uc16_buffer.get(), length); | 542 TestExternalResource resource(uc16_buffer.get(), length); |
544 i::Handle<i::String> uc16_string( | 543 i::Handle<i::String> uc16_string( |
545 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); | 544 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); |
546 | 545 |
547 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( | 546 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( |
548 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); | 547 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); |
549 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); | 548 i::GenericStringUtf16CharacterStream string_stream(one_byte_string, start, |
| 549 end); |
550 i::Utf8ToUtf16CharacterStream utf8_stream( | 550 i::Utf8ToUtf16CharacterStream utf8_stream( |
551 reinterpret_cast<const i::byte*>(ascii_source), end); | 551 reinterpret_cast<const i::byte*>(one_byte_source), end); |
552 utf8_stream.SeekForward(start); | 552 utf8_stream.SeekForward(start); |
553 | 553 |
554 unsigned i = start; | 554 unsigned i = start; |
555 while (i < end) { | 555 while (i < end) { |
556 // Read streams one char at a time | 556 // Read streams one char at a time |
557 CHECK_EQU(i, uc16_stream.pos()); | 557 CHECK_EQU(i, uc16_stream.pos()); |
558 CHECK_EQU(i, string_stream.pos()); | 558 CHECK_EQU(i, string_stream.pos()); |
559 CHECK_EQU(i, utf8_stream.pos()); | 559 CHECK_EQU(i, utf8_stream.pos()); |
560 int32_t c0 = ascii_source[i]; | 560 int32_t c0 = one_byte_source[i]; |
561 int32_t c1 = uc16_stream.Advance(); | 561 int32_t c1 = uc16_stream.Advance(); |
562 int32_t c2 = string_stream.Advance(); | 562 int32_t c2 = string_stream.Advance(); |
563 int32_t c3 = utf8_stream.Advance(); | 563 int32_t c3 = utf8_stream.Advance(); |
564 i++; | 564 i++; |
565 CHECK_EQ(c0, c1); | 565 CHECK_EQ(c0, c1); |
566 CHECK_EQ(c0, c2); | 566 CHECK_EQ(c0, c2); |
567 CHECK_EQ(c0, c3); | 567 CHECK_EQ(c0, c3); |
568 CHECK_EQU(i, uc16_stream.pos()); | 568 CHECK_EQU(i, uc16_stream.pos()); |
569 CHECK_EQU(i, string_stream.pos()); | 569 CHECK_EQU(i, string_stream.pos()); |
570 CHECK_EQU(i, utf8_stream.pos()); | 570 CHECK_EQU(i, utf8_stream.pos()); |
571 } | 571 } |
572 while (i > start + sub_length / 4) { | 572 while (i > start + sub_length / 4) { |
573 // Pushback, re-read, pushback again. | 573 // Pushback, re-read, pushback again. |
574 int32_t c0 = ascii_source[i - 1]; | 574 int32_t c0 = one_byte_source[i - 1]; |
575 CHECK_EQU(i, uc16_stream.pos()); | 575 CHECK_EQU(i, uc16_stream.pos()); |
576 CHECK_EQU(i, string_stream.pos()); | 576 CHECK_EQU(i, string_stream.pos()); |
577 CHECK_EQU(i, utf8_stream.pos()); | 577 CHECK_EQU(i, utf8_stream.pos()); |
578 uc16_stream.PushBack(c0); | 578 uc16_stream.PushBack(c0); |
579 string_stream.PushBack(c0); | 579 string_stream.PushBack(c0); |
580 utf8_stream.PushBack(c0); | 580 utf8_stream.PushBack(c0); |
581 i--; | 581 i--; |
582 CHECK_EQU(i, uc16_stream.pos()); | 582 CHECK_EQU(i, uc16_stream.pos()); |
583 CHECK_EQU(i, string_stream.pos()); | 583 CHECK_EQU(i, string_stream.pos()); |
584 CHECK_EQU(i, utf8_stream.pos()); | 584 CHECK_EQU(i, utf8_stream.pos()); |
(...skipping 22 matching lines...) Expand all Loading... |
607 i = halfway; | 607 i = halfway; |
608 CHECK_EQU(i, uc16_stream.pos()); | 608 CHECK_EQU(i, uc16_stream.pos()); |
609 CHECK_EQU(i, string_stream.pos()); | 609 CHECK_EQU(i, string_stream.pos()); |
610 CHECK_EQU(i, utf8_stream.pos()); | 610 CHECK_EQU(i, utf8_stream.pos()); |
611 | 611 |
612 while (i < end) { | 612 while (i < end) { |
613 // Read streams one char at a time | 613 // Read streams one char at a time |
614 CHECK_EQU(i, uc16_stream.pos()); | 614 CHECK_EQU(i, uc16_stream.pos()); |
615 CHECK_EQU(i, string_stream.pos()); | 615 CHECK_EQU(i, string_stream.pos()); |
616 CHECK_EQU(i, utf8_stream.pos()); | 616 CHECK_EQU(i, utf8_stream.pos()); |
617 int32_t c0 = ascii_source[i]; | 617 int32_t c0 = one_byte_source[i]; |
618 int32_t c1 = uc16_stream.Advance(); | 618 int32_t c1 = uc16_stream.Advance(); |
619 int32_t c2 = string_stream.Advance(); | 619 int32_t c2 = string_stream.Advance(); |
620 int32_t c3 = utf8_stream.Advance(); | 620 int32_t c3 = utf8_stream.Advance(); |
621 i++; | 621 i++; |
622 CHECK_EQ(c0, c1); | 622 CHECK_EQ(c0, c1); |
623 CHECK_EQ(c0, c2); | 623 CHECK_EQ(c0, c2); |
624 CHECK_EQ(c0, c3); | 624 CHECK_EQ(c0, c3); |
625 CHECK_EQU(i, uc16_stream.pos()); | 625 CHECK_EQU(i, uc16_stream.pos()); |
626 CHECK_EQU(i, string_stream.pos()); | 626 CHECK_EQU(i, string_stream.pos()); |
627 CHECK_EQU(i, utf8_stream.pos()); | 627 CHECK_EQU(i, utf8_stream.pos()); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); | 803 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); |
804 scanner.Next(); // Current token is now the regexp literal. | 804 scanner.Next(); // Current token is now the regexp literal. |
805 i::Zone zone(CcTest::i_isolate()); | 805 i::Zone zone(CcTest::i_isolate()); |
806 i::AstValueFactory ast_value_factory(&zone, | 806 i::AstValueFactory ast_value_factory(&zone, |
807 CcTest::i_isolate()->heap()->HashSeed()); | 807 CcTest::i_isolate()->heap()->HashSeed()); |
808 ast_value_factory.Internalize(CcTest::i_isolate()); | 808 ast_value_factory.Internalize(CcTest::i_isolate()); |
809 i::Handle<i::String> val = | 809 i::Handle<i::String> val = |
810 scanner.CurrentSymbol(&ast_value_factory)->string(); | 810 scanner.CurrentSymbol(&ast_value_factory)->string(); |
811 i::DisallowHeapAllocation no_alloc; | 811 i::DisallowHeapAllocation no_alloc; |
812 i::String::FlatContent content = val->GetFlatContent(); | 812 i::String::FlatContent content = val->GetFlatContent(); |
813 CHECK(content.IsAscii()); | 813 CHECK(content.IsOneByte()); |
814 i::Vector<const uint8_t> actual = content.ToOneByteVector(); | 814 i::Vector<const uint8_t> actual = content.ToOneByteVector(); |
815 for (int i = 0; i < actual.length(); i++) { | 815 for (int i = 0; i < actual.length(); i++) { |
816 CHECK_NE('\0', expected[i]); | 816 CHECK_NE('\0', expected[i]); |
817 CHECK_EQ(expected[i], actual[i]); | 817 CHECK_EQ(expected[i], actual[i]); |
818 } | 818 } |
819 } | 819 } |
820 | 820 |
821 | 821 |
822 TEST(RegExpScanning) { | 822 TEST(RegExpScanning) { |
823 v8::V8::Initialize(); | 823 v8::V8::Initialize(); |
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2788 // Tests function name inferring in cases where some parts of the inferred | 2788 // Tests function name inferring in cases where some parts of the inferred |
2789 // function name are two-byte strings. | 2789 // function name are two-byte strings. |
2790 i::FLAG_allow_natives_syntax = true; | 2790 i::FLAG_allow_natives_syntax = true; |
2791 v8::Isolate* isolate = CcTest::isolate(); | 2791 v8::Isolate* isolate = CcTest::isolate(); |
2792 v8::HandleScope scope(isolate); | 2792 v8::HandleScope scope(isolate); |
2793 LocalContext env; | 2793 LocalContext env; |
2794 uint16_t* two_byte_source = AsciiToTwoByteString( | 2794 uint16_t* two_byte_source = AsciiToTwoByteString( |
2795 "var obj1 = { oXj2 : { foo1: function() {} } }; " | 2795 "var obj1 = { oXj2 : { foo1: function() {} } }; " |
2796 "%FunctionGetInferredName(obj1.oXj2.foo1)"); | 2796 "%FunctionGetInferredName(obj1.oXj2.foo1)"); |
2797 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); | 2797 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
2798 // Make it really non-ASCII (replace the Xs with a non-ASCII character). | 2798 // Make it really non-Latin1 (replace the Xs with a non-Latin1 character). |
2799 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; | 2799 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; |
2800 v8::Local<v8::String> source = | 2800 v8::Local<v8::String> source = |
2801 v8::String::NewFromTwoByte(isolate, two_byte_source); | 2801 v8::String::NewFromTwoByte(isolate, two_byte_source); |
2802 v8::Local<v8::Value> result = CompileRun(source); | 2802 v8::Local<v8::Value> result = CompileRun(source); |
2803 CHECK(result->IsString()); | 2803 CHECK(result->IsString()); |
2804 v8::Local<v8::String> expected_name = | 2804 v8::Local<v8::String> expected_name = |
2805 v8::String::NewFromTwoByte(isolate, two_byte_name); | 2805 v8::String::NewFromTwoByte(isolate, two_byte_name); |
2806 CHECK(result->Equals(expected_name)); | 2806 CHECK(result->Equals(expected_name)); |
2807 i::DeleteArray(two_byte_source); | 2807 i::DeleteArray(two_byte_source); |
2808 i::DeleteArray(two_byte_name); | 2808 i::DeleteArray(two_byte_name); |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3385 const char* statement_data[] = { | 3385 const char* statement_data[] = { |
3386 "super = x", | 3386 "super = x", |
3387 "y = super", | 3387 "y = super", |
3388 "f(super)", | 3388 "f(super)", |
3389 NULL}; | 3389 NULL}; |
3390 | 3390 |
3391 static const ParserFlag always_flags[] = {kAllowClasses}; | 3391 static const ParserFlag always_flags[] = {kAllowClasses}; |
3392 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 3392 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
3393 always_flags, arraysize(always_flags)); | 3393 always_flags, arraysize(always_flags)); |
3394 } | 3394 } |
OLD | NEW |