| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include <stdio.h> |
| 29 | 30 |
| 30 #include "v8.h" | 31 #include "v8.h" |
| 31 | 32 |
| 32 #include "token.h" | 33 #include "token.h" |
| 33 #include "scanner.h" | 34 #include "scanner.h" |
| 34 #include "parser.h" | 35 #include "parser.h" |
| 35 #include "utils.h" | 36 #include "utils.h" |
| 36 #include "execution.h" | 37 #include "execution.h" |
| 37 | 38 #include "scanner.h" |
| 39 #include "preparser.h" |
| 38 #include "cctest.h" | 40 #include "cctest.h" |
| 39 | 41 |
| 40 namespace i = ::v8::internal; | 42 namespace i = ::v8::internal; |
| 41 | 43 |
| 42 TEST(KeywordMatcher) { | 44 TEST(KeywordMatcher) { |
| 43 struct KeywordToken { | 45 struct KeywordToken { |
| 44 const char* keyword; | 46 const char* keyword; |
| 45 i::Token::Value token; | 47 i::Token::Value token; |
| 46 }; | 48 }; |
| 47 | 49 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 i::Scanner::Location error_location = | 234 i::Scanner::Location error_location = |
| 233 pre_impl->MessageLocation(); | 235 pre_impl->MessageLocation(); |
| 234 // Error is at "z" in source, location 10..11. | 236 // Error is at "z" in source, location 10..11. |
| 235 CHECK_EQ(10, error_location.beg_pos); | 237 CHECK_EQ(10, error_location.beg_pos); |
| 236 CHECK_EQ(11, error_location.end_pos); | 238 CHECK_EQ(11, error_location.end_pos); |
| 237 // Should not crash. | 239 // Should not crash. |
| 238 const char* message = pre_impl->BuildMessage(); | 240 const char* message = pre_impl->BuildMessage(); |
| 239 i::Vector<const char*> args = pre_impl->BuildArgs(); | 241 i::Vector<const char*> args = pre_impl->BuildArgs(); |
| 240 CHECK_GT(strlen(message), 0); | 242 CHECK_GT(strlen(message), 0); |
| 241 } | 243 } |
| 244 |
| 245 |
| 246 TEST(StandAlonePreParser) { |
| 247 int marker; |
| 248 i::StackGuard::SetStackLimit( |
| 249 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 250 |
| 251 const char* programs[] = { |
| 252 "{label: 42}", |
| 253 "var x = 42;", |
| 254 "function foo(x, y) { return x + y; }", |
| 255 "native function foo(); return %ArgleBargle(glop);", |
| 256 NULL |
| 257 }; |
| 258 |
| 259 for (int i = 0; programs[i]; i++) { |
| 260 const char* program = programs[i]; |
| 261 unibrow::Utf8InputBuffer<256> stream(program, strlen(program)); |
| 262 i::CompleteParserRecorder log; |
| 263 i::Scanner scanner; |
| 264 scanner.Initialize(i::Handle<i::String>::null(), &stream, i::JAVASCRIPT); |
| 265 i::preparser::PreParser<i::Scanner, i::CompleteParserRecorder> preparser; |
| 266 bool result = preparser.PreParseProgram(&scanner, &log, true); |
| 267 CHECK(result); |
| 268 i::ScriptDataImpl data(log.ExtractData()); |
| 269 CHECK(!data.has_error()); |
| 270 } |
| 271 } |
| OLD | NEW |