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 SkipWhiteSpace(); | |
173 Scan(); | |
174 } | |
175 }; | |
176 | |
177 | |
178 // 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) |
179 // or here (for a stand-alone preparser). | 162 // or here (for a stand-alone preparser). |
180 | 163 |
181 void FatalProcessOutOfMemory(const char* reason) { | 164 void FatalProcessOutOfMemory(const char* reason) { |
182 V8_Fatal(__FILE__, __LINE__, reason); | 165 V8_Fatal(__FILE__, __LINE__, reason); |
183 } | 166 } |
184 | 167 |
185 bool EnableSlowAsserts() { return true; } | 168 bool EnableSlowAsserts() { return true; } |
186 | 169 |
187 } // namespace internal. | 170 } // namespace internal. |
188 | 171 |
189 | 172 |
190 UnicodeInputStream::~UnicodeInputStream() { } | 173 UnicodeInputStream::~UnicodeInputStream() { } |
191 | 174 |
192 | 175 |
193 PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) { | 176 PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) { |
194 internal::InputStreamUTF16Buffer buffer(input); | 177 internal::InputStreamUTF16Buffer buffer(input); |
195 uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack; | 178 uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack; |
196 internal::UnicodeCache unicode_cache; | 179 internal::UnicodeCache unicode_cache; |
197 internal::StandAloneJavaScriptScanner scanner(&unicode_cache); | 180 internal::JavaScriptScanner scanner(&unicode_cache); |
198 scanner.Initialize(&buffer); | 181 scanner.Initialize(&buffer); |
199 internal::CompleteParserRecorder recorder; | 182 internal::CompleteParserRecorder recorder; |
200 preparser::PreParser::PreParseResult result = | 183 preparser::PreParser::PreParseResult result = |
201 preparser::PreParser::PreParseProgram(&scanner, | 184 preparser::PreParser::PreParseProgram(&scanner, |
202 &recorder, | 185 &recorder, |
203 true, | 186 true, |
204 stack_limit); | 187 stack_limit); |
205 if (result == preparser::PreParser::kPreParseStackOverflow) { | 188 if (result == preparser::PreParser::kPreParseStackOverflow) { |
206 return PreParserData::StackOverflow(); | 189 return PreParserData::StackOverflow(); |
207 } | 190 } |
208 internal::Vector<unsigned> pre_data = recorder.ExtractData(); | 191 internal::Vector<unsigned> pre_data = recorder.ExtractData(); |
209 size_t size = pre_data.length() * sizeof(pre_data[0]); | 192 size_t size = pre_data.length() * sizeof(pre_data[0]); |
210 unsigned char* data = reinterpret_cast<unsigned char*>(pre_data.start()); | 193 unsigned char* data = reinterpret_cast<unsigned char*>(pre_data.start()); |
211 return PreParserData(size, data); | 194 return PreParserData(size, data); |
212 } | 195 } |
213 | 196 |
214 } // namespace v8. | 197 } // namespace v8. |
215 | 198 |
216 | 199 |
217 // Used by ASSERT macros and other immediate exits. | 200 // Used by ASSERT macros and other immediate exits. |
218 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, ...) { |
219 exit(EXIT_FAILURE); | 202 exit(EXIT_FAILURE); |
220 } | 203 } |
OLD | NEW |