OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // Limit of pushbacks before new allocation is necessary. | 151 // Limit of pushbacks before new allocation is necessary. |
152 uc16* pushback_buffer_; | 152 uc16* pushback_buffer_; |
153 // Only if that pushback buffer at the start of buffer_ isn't sufficient | 153 // Only if that pushback buffer at the start of buffer_ isn't sufficient |
154 // is the following used. | 154 // is the following used. |
155 const uc16* pushback_buffer_end_cache_; | 155 const uc16* pushback_buffer_end_cache_; |
156 uc16* pushback_buffer_backing_; | 156 uc16* pushback_buffer_backing_; |
157 unsigned pushback_buffer_backing_size_; | 157 unsigned pushback_buffer_backing_size_; |
158 }; | 158 }; |
159 | 159 |
160 | 160 |
161 class StandAloneJavaScriptScanner : public JavaScriptScanner { | |
162 public: | |
163 explicit StandAloneJavaScriptScanner(UnicodeCache* unicode_cache) | |
164 : JavaScriptScanner(unicode_cache) { } | |
165 | |
166 void Initialize(UC16CharacterStream* source) { | |
167 source_ = source; | |
168 Init(); | |
169 // Skip initial whitespace allowing HTML comment ends just like | |
170 // after a newline and scan first token. | |
171 has_line_terminator_before_next_ = true; | |
172 has_multiline_comment_before_next_ = false; | |
173 SkipWhiteSpace(); | |
174 Scan(); | |
175 } | |
176 }; | |
177 | |
178 | |
179 // Functions declared by allocation.h and implemented in both api.cc (for v8) | 161 // Functions declared by allocation.h and implemented in both api.cc (for v8) |
180 // or here (for a stand-alone preparser). | 162 // or here (for a stand-alone preparser). |
181 | 163 |
182 void FatalProcessOutOfMemory(const char* reason) { | 164 void FatalProcessOutOfMemory(const char* reason) { |
183 V8_Fatal(__FILE__, __LINE__, reason); | 165 V8_Fatal(__FILE__, __LINE__, reason); |
184 } | 166 } |
185 | 167 |
186 bool EnableSlowAsserts() { return true; } | 168 bool EnableSlowAsserts() { return true; } |
187 | 169 |
188 } // namespace internal. | 170 } // namespace internal. |
189 | 171 |
190 | 172 |
191 UnicodeInputStream::~UnicodeInputStream() { } | 173 UnicodeInputStream::~UnicodeInputStream() { } |
192 | 174 |
193 | 175 |
194 PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) { | 176 PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) { |
195 internal::InputStreamUTF16Buffer buffer(input); | 177 internal::InputStreamUTF16Buffer buffer(input); |
196 uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack; | 178 uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack; |
197 internal::UnicodeCache unicode_cache; | 179 internal::UnicodeCache unicode_cache; |
198 internal::StandAloneJavaScriptScanner scanner(&unicode_cache); | 180 internal::JavaScriptScanner scanner(&unicode_cache); |
199 scanner.Initialize(&buffer); | 181 scanner.Initialize(&buffer); |
200 internal::CompleteParserRecorder recorder; | 182 internal::CompleteParserRecorder recorder; |
201 preparser::PreParser::PreParseResult result = | 183 preparser::PreParser::PreParseResult result = |
202 preparser::PreParser::PreParseProgram(&scanner, | 184 preparser::PreParser::PreParseProgram(&scanner, |
203 &recorder, | 185 &recorder, |
204 true, | 186 true, |
205 stack_limit); | 187 stack_limit); |
206 if (result == preparser::PreParser::kPreParseStackOverflow) { | 188 if (result == preparser::PreParser::kPreParseStackOverflow) { |
207 return PreParserData::StackOverflow(); | 189 return PreParserData::StackOverflow(); |
208 } | 190 } |
209 internal::Vector<unsigned> pre_data = recorder.ExtractData(); | 191 internal::Vector<unsigned> pre_data = recorder.ExtractData(); |
210 size_t size = pre_data.length() * sizeof(pre_data[0]); | 192 size_t size = pre_data.length() * sizeof(pre_data[0]); |
211 unsigned char* data = reinterpret_cast<unsigned char*>(pre_data.start()); | 193 unsigned char* data = reinterpret_cast<unsigned char*>(pre_data.start()); |
212 return PreParserData(size, data); | 194 return PreParserData(size, data); |
213 } | 195 } |
214 | 196 |
215 } // namespace v8. | 197 } // namespace v8. |
216 | 198 |
217 | 199 |
218 // Used by ASSERT macros and other immediate exits. | 200 // Used by ASSERT macros and other immediate exits. |
219 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { | 201 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
220 exit(EXIT_FAILURE); | 202 exit(EXIT_FAILURE); |
221 } | 203 } |
OLD | NEW |