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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 scanner.Initialize(&stream); | 100 scanner.Initialize(&stream); |
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 | 111 |
111 // Regression test. See: | 112 // Regression test. See: |
112 // http://code.google.com/p/chromium/issues/detail?id=53548 | 113 // http://code.google.com/p/chromium/issues/detail?id=53548 |
113 // Tests that --> is correctly interpreted as comment-to-end-of-line if there | 114 // Tests that --> is correctly interpreted as comment-to-end-of-line if there |
114 // is only whitespace before it on the line (with comments considered as | 115 // is only whitespace before it on the line (with comments considered as |
115 // whitespace, even a multiline-comment containing a newline). | 116 // whitespace, even a multiline-comment containing a newline). |
116 // This was not the case if it occurred before the first real token | 117 // This was not the case if it occurred before the first real token |
117 // in the input. | 118 // in the input. |
118 const char* tests[] = { | 119 const char* tests[] = { |
119 // Before first real token. | 120 // Before first real token. |
(...skipping 17 matching lines...) Expand all Loading... |
137 NULL | 138 NULL |
138 }; | 139 }; |
139 | 140 |
140 // Parser/Scanner needs a stack limit. | 141 // Parser/Scanner needs a stack limit. |
141 int marker; | 142 int marker; |
142 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 143 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
143 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 144 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
144 | 145 |
145 for (int i = 0; tests[i]; i++) { | 146 for (int i = 0; tests[i]; i++) { |
146 v8::ScriptData* data = | 147 v8::ScriptData* data = |
147 v8::ScriptData::PreCompile(tests[i], i::StrLength(tests[i])); | 148 v8::ScriptData::PreCompile(isolate, tests[i], i::StrLength(tests[i])); |
148 CHECK(data != NULL && !data->HasError()); | 149 CHECK(data != NULL && !data->HasError()); |
149 delete data; | 150 delete data; |
150 } | 151 } |
151 | 152 |
152 for (int i = 0; fail_tests[i]; i++) { | 153 for (int i = 0; fail_tests[i]; i++) { |
153 v8::ScriptData* data = | 154 v8::ScriptData* data = v8::ScriptData::PreCompile( |
154 v8::ScriptData::PreCompile(fail_tests[i], i::StrLength(fail_tests[i])); | 155 isolate, fail_tests[i], i::StrLength(fail_tests[i])); |
155 CHECK(data == NULL || data->HasError()); | 156 CHECK(data == NULL || data->HasError()); |
156 delete data; | 157 delete data; |
157 } | 158 } |
158 } | 159 } |
159 | 160 |
160 | 161 |
161 class ScriptResource : public v8::String::ExternalAsciiStringResource { | 162 class ScriptResource : public v8::String::ExternalAsciiStringResource { |
162 public: | 163 public: |
163 ScriptResource(const char* data, size_t length) | 164 ScriptResource(const char* data, size_t length) |
164 : data_(data), length_(length) { } | 165 : data_(data), length_(length) { } |
(...skipping 27 matching lines...) Expand all Loading... |
192 " f\\u006fr: 'keyword propertyname with escape'};" | 193 " f\\u006fr: 'keyword propertyname with escape'};" |
193 "var v = /RegExp Literal/;" | 194 "var v = /RegExp Literal/;" |
194 "var w = /RegExp Literal\\u0020With Escape/gin;" | 195 "var w = /RegExp Literal\\u0020With Escape/gin;" |
195 "var y = { get getter() { return 42; }, " | 196 "var y = { get getter() { return 42; }, " |
196 " set setter(v) { this.value = v; }};"; | 197 " set setter(v) { this.value = v; }};"; |
197 int source_length = i::StrLength(source); | 198 int source_length = i::StrLength(source); |
198 const char* error_source = "var x = y z;"; | 199 const char* error_source = "var x = y z;"; |
199 int error_source_length = i::StrLength(error_source); | 200 int error_source_length = i::StrLength(error_source); |
200 | 201 |
201 v8::ScriptData* preparse = | 202 v8::ScriptData* preparse = |
202 v8::ScriptData::PreCompile(source, source_length); | 203 v8::ScriptData::PreCompile(isolate, source, source_length); |
203 CHECK(!preparse->HasError()); | 204 CHECK(!preparse->HasError()); |
204 bool lazy_flag = i::FLAG_lazy; | 205 bool lazy_flag = i::FLAG_lazy; |
205 { | 206 { |
206 i::FLAG_lazy = true; | 207 i::FLAG_lazy = true; |
207 ScriptResource* resource = new ScriptResource(source, source_length); | 208 ScriptResource* resource = new ScriptResource(source, source_length); |
208 v8::Local<v8::String> script_source = v8::String::NewExternal(resource); | 209 v8::Local<v8::String> script_source = v8::String::NewExternal(resource); |
209 v8::Script::Compile(script_source, NULL, preparse); | 210 v8::Script::Compile(script_source, NULL, preparse); |
210 } | 211 } |
211 | 212 |
212 { | 213 { |
213 i::FLAG_lazy = false; | 214 i::FLAG_lazy = false; |
214 | 215 |
215 ScriptResource* resource = new ScriptResource(source, source_length); | 216 ScriptResource* resource = new ScriptResource(source, source_length); |
216 v8::Local<v8::String> script_source = v8::String::NewExternal(resource); | 217 v8::Local<v8::String> script_source = v8::String::NewExternal(resource); |
217 v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>()); | 218 v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>()); |
218 } | 219 } |
219 delete preparse; | 220 delete preparse; |
220 i::FLAG_lazy = lazy_flag; | 221 i::FLAG_lazy = lazy_flag; |
221 | 222 |
222 // Syntax error. | 223 // Syntax error. |
223 v8::ScriptData* error_preparse = | 224 v8::ScriptData* error_preparse = |
224 v8::ScriptData::PreCompile(error_source, error_source_length); | 225 v8::ScriptData::PreCompile(isolate, error_source, error_source_length); |
225 CHECK(error_preparse->HasError()); | 226 CHECK(error_preparse->HasError()); |
226 i::ScriptDataImpl *pre_impl = | 227 i::ScriptDataImpl *pre_impl = |
227 reinterpret_cast<i::ScriptDataImpl*>(error_preparse); | 228 reinterpret_cast<i::ScriptDataImpl*>(error_preparse); |
228 i::Scanner::Location error_location = | 229 i::Scanner::Location error_location = |
229 pre_impl->MessageLocation(); | 230 pre_impl->MessageLocation(); |
230 // Error is at "z" in source, location 10..11. | 231 // Error is at "z" in source, location 10..11. |
231 CHECK_EQ(10, error_location.beg_pos); | 232 CHECK_EQ(10, error_location.beg_pos); |
232 CHECK_EQ(11, error_location.end_pos); | 233 CHECK_EQ(11, error_location.end_pos); |
233 // Should not crash. | 234 // Should not crash. |
234 const char* message = pre_impl->BuildMessage(); | 235 const char* message = pre_impl->BuildMessage(); |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 " b = function() { \n" | 1319 " b = function() { \n" |
1319 " 01; \n" | 1320 " 01; \n" |
1320 " }; \n" | 1321 " }; \n" |
1321 "}; \n"; | 1322 "}; \n"; |
1322 v8::Script::Compile(v8::String::New(script)); | 1323 v8::Script::Compile(v8::String::New(script)); |
1323 CHECK(try_catch.HasCaught()); | 1324 CHECK(try_catch.HasCaught()); |
1324 v8::String::Utf8Value exception(try_catch.Exception()); | 1325 v8::String::Utf8Value exception(try_catch.Exception()); |
1325 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1326 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
1326 *exception); | 1327 *exception); |
1327 } | 1328 } |
OLD | NEW |