| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 101 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 102 CHECK_EQ(i::Token::EOS, scanner.Next()); | 102 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 | 107 |
| 108 TEST(ScanHTMLEndComments) { | 108 TEST(ScanHTMLEndComments) { |
| 109 v8::V8::Initialize(); | 109 v8::V8::Initialize(); |
| 110 v8::Isolate* isolate = CcTest::isolate(); | 110 v8::Isolate* isolate = CcTest::isolate(); |
| 111 v8::HandleScope handles(isolate); |
| 111 | 112 |
| 112 // Regression test. See: | 113 // Regression test. See: |
| 113 // http://code.google.com/p/chromium/issues/detail?id=53548 | 114 // http://code.google.com/p/chromium/issues/detail?id=53548 |
| 114 // Tests that --> is correctly interpreted as comment-to-end-of-line if there | 115 // Tests that --> is correctly interpreted as comment-to-end-of-line if there |
| 115 // is only whitespace before it on the line (with comments considered as | 116 // is only whitespace before it on the line (with comments considered as |
| 116 // whitespace, even a multiline-comment containing a newline). | 117 // whitespace, even a multiline-comment containing a newline). |
| 117 // This was not the case if it occurred before the first real token | 118 // This was not the case if it occurred before the first real token |
| 118 // in the input. | 119 // in the input. |
| 119 const char* tests[] = { | 120 const char* tests[] = { |
| 120 // Before first real token. | 121 // Before first real token. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 "var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n", | 138 "var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n", |
| 138 NULL | 139 NULL |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 // Parser/Scanner needs a stack limit. | 142 // Parser/Scanner needs a stack limit. |
| 142 int marker; | 143 int marker; |
| 143 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 144 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 144 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 145 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 145 | 146 |
| 146 for (int i = 0; tests[i]; i++) { | 147 for (int i = 0; tests[i]; i++) { |
| 147 v8::ScriptData* data = | 148 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
| 148 v8::ScriptData::PreCompile(isolate, tests[i], i::StrLength(tests[i])); | 149 isolate, tests[i], v8::String::kNormalString, i::StrLength(tests[i])); |
| 150 v8::ScriptData* data = v8::ScriptData::PreCompile(source); |
| 149 CHECK(data != NULL && !data->HasError()); | 151 CHECK(data != NULL && !data->HasError()); |
| 150 delete data; | 152 delete data; |
| 151 } | 153 } |
| 152 | 154 |
| 153 for (int i = 0; fail_tests[i]; i++) { | 155 for (int i = 0; fail_tests[i]; i++) { |
| 154 v8::ScriptData* data = v8::ScriptData::PreCompile( | 156 v8::Handle<v8::String> source = |
| 155 isolate, fail_tests[i], i::StrLength(fail_tests[i])); | 157 v8::String::NewFromUtf8(isolate, |
| 158 fail_tests[i], |
| 159 v8::String::kNormalString, |
| 160 i::StrLength(fail_tests[i])); |
| 161 v8::ScriptData* data = v8::ScriptData::PreCompile(source); |
| 156 CHECK(data == NULL || data->HasError()); | 162 CHECK(data == NULL || data->HasError()); |
| 157 delete data; | 163 delete data; |
| 158 } | 164 } |
| 159 } | 165 } |
| 160 | 166 |
| 161 | 167 |
| 162 class ScriptResource : public v8::String::ExternalAsciiStringResource { | 168 class ScriptResource : public v8::String::ExternalAsciiStringResource { |
| 163 public: | 169 public: |
| 164 ScriptResource(const char* data, size_t length) | 170 ScriptResource(const char* data, size_t length) |
| 165 : data_(data), length_(length) { } | 171 : data_(data), length_(length) { } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 192 " 42: 'number literal', for: 'keyword as propertyName', " | 198 " 42: 'number literal', for: 'keyword as propertyName', " |
| 193 " f\\u006fr: 'keyword propertyname with escape'};" | 199 " f\\u006fr: 'keyword propertyname with escape'};" |
| 194 "var v = /RegExp Literal/;" | 200 "var v = /RegExp Literal/;" |
| 195 "var w = /RegExp Literal\\u0020With Escape/gin;" | 201 "var w = /RegExp Literal\\u0020With Escape/gin;" |
| 196 "var y = { get getter() { return 42; }, " | 202 "var y = { get getter() { return 42; }, " |
| 197 " set setter(v) { this.value = v; }};"; | 203 " set setter(v) { this.value = v; }};"; |
| 198 int source_length = i::StrLength(source); | 204 int source_length = i::StrLength(source); |
| 199 const char* error_source = "var x = y z;"; | 205 const char* error_source = "var x = y z;"; |
| 200 int error_source_length = i::StrLength(error_source); | 206 int error_source_length = i::StrLength(error_source); |
| 201 | 207 |
| 202 v8::ScriptData* preparse = | 208 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( |
| 203 v8::ScriptData::PreCompile(isolate, source, source_length); | 209 isolate, source, v8::String::kNormalString, source_length)); |
| 204 CHECK(!preparse->HasError()); | 210 CHECK(!preparse->HasError()); |
| 205 bool lazy_flag = i::FLAG_lazy; | 211 bool lazy_flag = i::FLAG_lazy; |
| 206 { | 212 { |
| 207 i::FLAG_lazy = true; | 213 i::FLAG_lazy = true; |
| 208 ScriptResource* resource = new ScriptResource(source, source_length); | 214 ScriptResource* resource = new ScriptResource(source, source_length); |
| 209 v8::Local<v8::String> script_source = | 215 v8::Local<v8::String> script_source = |
| 210 v8::String::NewExternal(isolate, resource); | 216 v8::String::NewExternal(isolate, resource); |
| 211 v8::Script::Compile(script_source, NULL, preparse); | 217 v8::Script::Compile(script_source, NULL, preparse); |
| 212 } | 218 } |
| 213 | 219 |
| 214 { | 220 { |
| 215 i::FLAG_lazy = false; | 221 i::FLAG_lazy = false; |
| 216 | 222 |
| 217 ScriptResource* resource = new ScriptResource(source, source_length); | 223 ScriptResource* resource = new ScriptResource(source, source_length); |
| 218 v8::Local<v8::String> script_source = | 224 v8::Local<v8::String> script_source = |
| 219 v8::String::NewExternal(isolate, resource); | 225 v8::String::NewExternal(isolate, resource); |
| 220 v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>()); | 226 v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>()); |
| 221 } | 227 } |
| 222 delete preparse; | 228 delete preparse; |
| 223 i::FLAG_lazy = lazy_flag; | 229 i::FLAG_lazy = lazy_flag; |
| 224 | 230 |
| 225 // Syntax error. | 231 // Syntax error. |
| 226 v8::ScriptData* error_preparse = | 232 v8::ScriptData* error_preparse = v8::ScriptData::PreCompile( |
| 227 v8::ScriptData::PreCompile(isolate, error_source, error_source_length); | 233 v8::String::NewFromUtf8(isolate, |
| 234 error_source, |
| 235 v8::String::kNormalString, |
| 236 error_source_length)); |
| 228 CHECK(error_preparse->HasError()); | 237 CHECK(error_preparse->HasError()); |
| 229 i::ScriptDataImpl *pre_impl = | 238 i::ScriptDataImpl *pre_impl = |
| 230 reinterpret_cast<i::ScriptDataImpl*>(error_preparse); | 239 reinterpret_cast<i::ScriptDataImpl*>(error_preparse); |
| 231 i::Scanner::Location error_location = | 240 i::Scanner::Location error_location = |
| 232 pre_impl->MessageLocation(); | 241 pre_impl->MessageLocation(); |
| 233 // Error is at "z" in source, location 10..11. | 242 // Error is at "z" in source, location 10..11. |
| 234 CHECK_EQ(10, error_location.beg_pos); | 243 CHECK_EQ(10, error_location.beg_pos); |
| 235 CHECK_EQ(11, error_location.end_pos); | 244 CHECK_EQ(11, error_location.end_pos); |
| 236 // Should not crash. | 245 // Should not crash. |
| 237 const char* message = pre_impl->BuildMessage(); | 246 const char* message = pre_impl->BuildMessage(); |
| (...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 " b = function() { \n" | 1338 " b = function() { \n" |
| 1330 " 01; \n" | 1339 " 01; \n" |
| 1331 " }; \n" | 1340 " }; \n" |
| 1332 "}; \n"; | 1341 "}; \n"; |
| 1333 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); | 1342 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); |
| 1334 CHECK(try_catch.HasCaught()); | 1343 CHECK(try_catch.HasCaught()); |
| 1335 v8::String::Utf8Value exception(try_catch.Exception()); | 1344 v8::String::Utf8Value exception(try_catch.Exception()); |
| 1336 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1345 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
| 1337 *exception); | 1346 *exception); |
| 1338 } | 1347 } |
| OLD | NEW |