OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 10 matching lines...) Expand all Loading... |
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 #ifndef V8_API_H_ | 28 #ifndef V8_API_H_ |
29 #define V8_API_H_ | 29 #define V8_API_H_ |
30 | 30 |
| 31 #include "apiutils.h" |
31 #include "factory.h" | 32 #include "factory.h" |
32 | 33 |
33 namespace v8 { | 34 namespace v8 { |
34 | 35 |
35 // Constants used in the implementation of the API. The most natural thing | 36 // Constants used in the implementation of the API. The most natural thing |
36 // would usually be to place these with the classes that use them, but | 37 // would usually be to place these with the classes that use them, but |
37 // we want to keep them out of v8.h because it is an externally | 38 // we want to keep them out of v8.h because it is an externally |
38 // visible file. | 39 // visible file. |
39 class Consts { | 40 class Consts { |
40 public: | 41 public: |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 private: | 153 private: |
153 Extension* extension_; | 154 Extension* extension_; |
154 RegisteredExtension* next_; | 155 RegisteredExtension* next_; |
155 RegisteredExtension* next_auto_; | 156 RegisteredExtension* next_auto_; |
156 ExtensionTraversalState state_; | 157 ExtensionTraversalState state_; |
157 static RegisteredExtension* first_extension_; | 158 static RegisteredExtension* first_extension_; |
158 static RegisteredExtension* first_auto_extension_; | 159 static RegisteredExtension* first_auto_extension_; |
159 }; | 160 }; |
160 | 161 |
161 | 162 |
162 class ImplementationUtilities { | |
163 public: | |
164 static v8::Handle<v8::Primitive> Undefined(); | |
165 static v8::Handle<v8::Primitive> Null(); | |
166 static v8::Handle<v8::Boolean> True(); | |
167 static v8::Handle<v8::Boolean> False(); | |
168 | |
169 static int GetNameCount(ExtensionConfiguration* that) { | |
170 return that->name_count_; | |
171 } | |
172 | |
173 static const char** GetNames(ExtensionConfiguration* that) { | |
174 return that->names_; | |
175 } | |
176 | |
177 static v8::Arguments NewArguments(Local<Value> data, | |
178 Local<Object> holder, | |
179 Local<Function> callee, | |
180 bool is_construct_call, | |
181 void** argv, int argc) { | |
182 return v8::Arguments(data, holder, callee, is_construct_call, argv, argc); | |
183 } | |
184 | |
185 // Introduce an alias for the handle scope data to allow non-friends | |
186 // to access the HandleScope data. | |
187 typedef v8::HandleScope::Data HandleScopeData; | |
188 | |
189 static HandleScopeData* CurrentHandleScope() { | |
190 return &v8::HandleScope::current_; | |
191 } | |
192 | |
193 #ifdef DEBUG | |
194 static void ZapHandleRange(void** begin, void** end) { | |
195 v8::HandleScope::ZapRange(begin, end); | |
196 } | |
197 #endif | |
198 }; | |
199 | |
200 | |
201 class Utils { | 163 class Utils { |
202 public: | 164 public: |
203 static bool ReportApiFailure(const char* location, const char* message); | 165 static bool ReportApiFailure(const char* location, const char* message); |
204 | 166 |
205 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); | 167 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); |
206 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); | 168 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); |
207 | 169 |
208 static inline Local<Context> ToLocal( | 170 static inline Local<Context> ToLocal( |
209 v8::internal::Handle<v8::internal::Context> obj); | 171 v8::internal::Handle<v8::internal::Context> obj); |
210 static inline Local<Value> ToLocal( | 172 static inline Local<Value> ToLocal( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 230 |
269 | 231 |
270 template <class T> | 232 template <class T> |
271 static inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { | 233 static inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { |
272 return reinterpret_cast<T*>(obj.location()); | 234 return reinterpret_cast<T*>(obj.location()); |
273 } | 235 } |
274 | 236 |
275 | 237 |
276 template <class T> | 238 template <class T> |
277 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( | 239 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( |
278 HandleScope* scope) { | 240 v8::HandleScope* scope) { |
279 return Utils::OpenHandle(*scope->Close(Utils::ToLocal(*this))); | 241 return Utils::OpenHandle(*scope->Close(Utils::ToLocal(*this))); |
280 } | 242 } |
281 | 243 |
282 | 244 |
283 // Implementations of ToLocal | 245 // Implementations of ToLocal |
284 | 246 |
285 #define MAKE_TO_LOCAL(Name, From, To) \ | 247 #define MAKE_TO_LOCAL(Name, From, To) \ |
286 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ | 248 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ |
287 return Local<To>(reinterpret_cast<To*>(obj.location())); \ | 249 return Local<To>(reinterpret_cast<To*>(obj.location())); \ |
288 } | 250 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 private: | 363 private: |
402 List<void**> blocks; | 364 List<void**> blocks; |
403 Object** spare; | 365 Object** spare; |
404 int call_depth; | 366 int call_depth; |
405 // Used as a stack to keep track of entered contexts. | 367 // Used as a stack to keep track of entered contexts. |
406 List<Handle<Object> > entered_contexts_; | 368 List<Handle<Object> > entered_contexts_; |
407 // Used as a stack to keep track of saved contexts. | 369 // Used as a stack to keep track of saved contexts. |
408 List<Handle<Object> > saved_contexts_; | 370 List<Handle<Object> > saved_contexts_; |
409 bool ignore_out_of_memory; | 371 bool ignore_out_of_memory; |
410 // This is only used for threading support. | 372 // This is only used for threading support. |
411 ImplementationUtilities::HandleScopeData handle_scope_data_; | 373 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; |
412 | 374 |
413 static void Iterate(ObjectVisitor* v, | 375 static void Iterate(ObjectVisitor* v, |
414 List<void**>* blocks, | 376 List<void**>* blocks, |
415 ImplementationUtilities::HandleScopeData* handle_data); | 377 v8::ImplementationUtilities::HandleScopeData* handle_data); |
416 char* RestoreThreadHelper(char* from); | 378 char* RestoreThreadHelper(char* from); |
417 char* ArchiveThreadHelper(char* to); | 379 char* ArchiveThreadHelper(char* to); |
418 | 380 |
419 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); | 381 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); |
420 }; | 382 }; |
421 | 383 |
422 | 384 |
423 static const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page | 385 static const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page |
424 | 386 |
425 | 387 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 429 |
468 | 430 |
469 void HandleScopeImplementer::DeleteExtensions(int extensions) { | 431 void HandleScopeImplementer::DeleteExtensions(int extensions) { |
470 if (spare != NULL) { | 432 if (spare != NULL) { |
471 DeleteArray(spare); | 433 DeleteArray(spare); |
472 spare = NULL; | 434 spare = NULL; |
473 } | 435 } |
474 for (int i = extensions; i > 1; --i) { | 436 for (int i = extensions; i > 1; --i) { |
475 void** block = blocks.RemoveLast(); | 437 void** block = blocks.RemoveLast(); |
476 #ifdef DEBUG | 438 #ifdef DEBUG |
477 ImplementationUtilities::ZapHandleRange(block, &block[kHandleBlockSize]); | 439 v8::ImplementationUtilities::ZapHandleRange(block, |
| 440 &block[kHandleBlockSize]); |
478 #endif | 441 #endif |
479 DeleteArray(block); | 442 DeleteArray(block); |
480 } | 443 } |
481 spare = reinterpret_cast<Object**>(blocks.RemoveLast()); | 444 spare = reinterpret_cast<Object**>(blocks.RemoveLast()); |
482 #ifdef DEBUG | 445 #ifdef DEBUG |
483 ImplementationUtilities::ZapHandleRange( | 446 v8::ImplementationUtilities::ZapHandleRange( |
484 reinterpret_cast<void**>(spare), | 447 reinterpret_cast<void**>(spare), |
485 reinterpret_cast<void**>(&spare[kHandleBlockSize])); | 448 reinterpret_cast<void**>(&spare[kHandleBlockSize])); |
486 #endif | 449 #endif |
487 } | 450 } |
488 | 451 |
489 } } // namespace v8::internal | 452 } } // namespace v8::internal |
490 | 453 |
491 #endif // V8_API_H_ | 454 #endif // V8_API_H_ |
OLD | NEW |