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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 static inline v8::internal::Handle<v8::internal::JSFunction> | 255 static inline v8::internal::Handle<v8::internal::JSFunction> |
256 OpenHandle(Function* data); | 256 OpenHandle(Function* data); |
257 static inline v8::internal::Handle<v8::internal::JSObject> | 257 static inline v8::internal::Handle<v8::internal::JSObject> |
258 OpenHandle(Message* message); | 258 OpenHandle(Message* message); |
259 static inline v8::internal::Handle<v8::internal::Context> | 259 static inline v8::internal::Handle<v8::internal::Context> |
260 OpenHandle(v8::Context* context); | 260 OpenHandle(v8::Context* context); |
261 static inline v8::internal::Handle<v8::internal::SignatureInfo> | 261 static inline v8::internal::Handle<v8::internal::SignatureInfo> |
262 OpenHandle(v8::Signature* sig); | 262 OpenHandle(v8::Signature* sig); |
263 static inline v8::internal::Handle<v8::internal::TypeSwitchInfo> | 263 static inline v8::internal::Handle<v8::internal::TypeSwitchInfo> |
264 OpenHandle(v8::TypeSwitch* that); | 264 OpenHandle(v8::TypeSwitch* that); |
| 265 static inline v8::internal::Handle<v8::internal::Proxy> |
| 266 OpenHandle(v8::External* that); |
265 }; | 267 }; |
266 | 268 |
267 | 269 |
268 template <class T> | 270 template <class T> |
269 static inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { | 271 static inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { |
270 return reinterpret_cast<T*>(obj.location()); | 272 return reinterpret_cast<T*>(obj.location()); |
271 } | 273 } |
272 | 274 |
273 | 275 |
274 template <class T> | 276 template <class T> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 MAKE_OPEN_HANDLE(Signature, SignatureInfo) | 320 MAKE_OPEN_HANDLE(Signature, SignatureInfo) |
319 MAKE_OPEN_HANDLE(TypeSwitch, TypeSwitchInfo) | 321 MAKE_OPEN_HANDLE(TypeSwitch, TypeSwitchInfo) |
320 MAKE_OPEN_HANDLE(Data, Object) | 322 MAKE_OPEN_HANDLE(Data, Object) |
321 MAKE_OPEN_HANDLE(Object, JSObject) | 323 MAKE_OPEN_HANDLE(Object, JSObject) |
322 MAKE_OPEN_HANDLE(Array, JSArray) | 324 MAKE_OPEN_HANDLE(Array, JSArray) |
323 MAKE_OPEN_HANDLE(String, String) | 325 MAKE_OPEN_HANDLE(String, String) |
324 MAKE_OPEN_HANDLE(Script, JSFunction) | 326 MAKE_OPEN_HANDLE(Script, JSFunction) |
325 MAKE_OPEN_HANDLE(Function, JSFunction) | 327 MAKE_OPEN_HANDLE(Function, JSFunction) |
326 MAKE_OPEN_HANDLE(Message, JSObject) | 328 MAKE_OPEN_HANDLE(Message, JSObject) |
327 MAKE_OPEN_HANDLE(Context, Context) | 329 MAKE_OPEN_HANDLE(Context, Context) |
| 330 MAKE_OPEN_HANDLE(External, Proxy) |
328 | 331 |
329 #undef MAKE_OPEN_HANDLE | 332 #undef MAKE_OPEN_HANDLE |
330 | 333 |
331 | 334 |
332 namespace internal { | 335 namespace internal { |
333 | 336 |
334 // This class is here in order to be able to declare it a friend of | 337 // This class is here in order to be able to declare it a friend of |
335 // HandleScope. Moving these methods to be members of HandleScope would be | 338 // HandleScope. Moving these methods to be members of HandleScope would be |
336 // neat in some ways, but it would expose external implementation details in | 339 // neat in some ways, but it would expose external implementation details in |
337 // our public header file, which is undesirable. | 340 // our public header file, which is undesirable. |
338 // | 341 // |
339 // There is a singleton instance of this class to hold the per-thread data. | 342 // There is a singleton instance of this class to hold the per-thread data. |
340 // For multithreaded V8 programs this data is copied in and out of storage | 343 // For multithreaded V8 programs this data is copied in and out of storage |
341 // so that the currently executing thread always has its own copy of this | 344 // so that the currently executing thread always has its own copy of this |
342 // data. | 345 // data. |
343 class HandleScopeImplementer { | 346 class HandleScopeImplementer { |
344 public: | 347 public: |
345 | 348 |
346 HandleScopeImplementer() | 349 HandleScopeImplementer() |
347 : blocks(0), | 350 : blocks(0), |
348 entered_contexts_(0), | 351 entered_contexts_(0), |
349 saved_contexts_(0), | 352 saved_contexts_(0) { |
350 saved_security_contexts_(0) { | |
351 Initialize(); | 353 Initialize(); |
352 } | 354 } |
353 | 355 |
354 void Initialize() { | 356 void Initialize() { |
355 blocks.Initialize(0); | 357 blocks.Initialize(0); |
356 entered_contexts_.Initialize(0); | 358 entered_contexts_.Initialize(0); |
357 saved_contexts_.Initialize(0); | 359 saved_contexts_.Initialize(0); |
358 saved_security_contexts_.Initialize(0); | |
359 spare = NULL; | 360 spare = NULL; |
360 ignore_out_of_memory = false; | 361 ignore_out_of_memory = false; |
361 call_depth = 0; | 362 call_depth = 0; |
362 } | 363 } |
363 | 364 |
364 static HandleScopeImplementer* instance(); | 365 static HandleScopeImplementer* instance(); |
365 | 366 |
366 // Threading support for handle data. | 367 // Threading support for handle data. |
367 static int ArchiveSpacePerThread(); | 368 static int ArchiveSpacePerThread(); |
368 static char* RestoreThread(char* from); | 369 static char* RestoreThread(char* from); |
(...skipping 15 matching lines...) Expand all Loading... |
384 inline bool LeaveLastContext(); | 385 inline bool LeaveLastContext(); |
385 | 386 |
386 // Returns the last entered context or an empty handle if no | 387 // Returns the last entered context or an empty handle if no |
387 // contexts have been entered. | 388 // contexts have been entered. |
388 inline Handle<Object> LastEnteredContext(); | 389 inline Handle<Object> LastEnteredContext(); |
389 | 390 |
390 inline void SaveContext(Handle<Object> context); | 391 inline void SaveContext(Handle<Object> context); |
391 inline Handle<Object> RestoreContext(); | 392 inline Handle<Object> RestoreContext(); |
392 inline bool HasSavedContexts(); | 393 inline bool HasSavedContexts(); |
393 | 394 |
394 inline void SaveSecurityContext(Handle<Object> context); | |
395 inline Handle<Object> RestoreSecurityContext(); | |
396 inline bool HasSavedSecurityContexts(); | |
397 | |
398 inline List<void**>* Blocks() { return &blocks; } | 395 inline List<void**>* Blocks() { return &blocks; } |
399 | 396 |
400 inline bool IgnoreOutOfMemory() { return ignore_out_of_memory; } | 397 inline bool IgnoreOutOfMemory() { return ignore_out_of_memory; } |
401 inline void SetIgnoreOutOfMemory(bool value) { ignore_out_of_memory = value; } | 398 inline void SetIgnoreOutOfMemory(bool value) { ignore_out_of_memory = value; } |
402 | 399 |
403 private: | 400 private: |
404 List<void**> blocks; | 401 List<void**> blocks; |
405 Object** spare; | 402 Object** spare; |
406 int call_depth; | 403 int call_depth; |
407 // Used as a stack to keep track of entered contexts. | 404 // Used as a stack to keep track of entered contexts. |
408 List<Handle<Object> > entered_contexts_; | 405 List<Handle<Object> > entered_contexts_; |
409 // Used as a stack to keep track of saved contexts. | 406 // Used as a stack to keep track of saved contexts. |
410 List<Handle<Object> > saved_contexts_; | 407 List<Handle<Object> > saved_contexts_; |
411 // Used as a stack to keep track of saved security contexts. | |
412 List<Handle<Object> > saved_security_contexts_; | |
413 bool ignore_out_of_memory; | 408 bool ignore_out_of_memory; |
414 // This is only used for threading support. | 409 // This is only used for threading support. |
415 ImplementationUtilities::HandleScopeData handle_scope_data_; | 410 ImplementationUtilities::HandleScopeData handle_scope_data_; |
416 | 411 |
417 static void Iterate(ObjectVisitor* v, | 412 static void Iterate(ObjectVisitor* v, |
418 List<void**>* blocks, | 413 List<void**>* blocks, |
419 ImplementationUtilities::HandleScopeData* handle_data); | 414 ImplementationUtilities::HandleScopeData* handle_data); |
420 char* RestoreThreadHelper(char* from); | 415 char* RestoreThreadHelper(char* from); |
421 char* ArchiveThreadHelper(char* to); | 416 char* ArchiveThreadHelper(char* to); |
422 | 417 |
(...skipping 12 matching lines...) Expand all Loading... |
435 Handle<Object> HandleScopeImplementer::RestoreContext() { | 430 Handle<Object> HandleScopeImplementer::RestoreContext() { |
436 return saved_contexts_.RemoveLast(); | 431 return saved_contexts_.RemoveLast(); |
437 } | 432 } |
438 | 433 |
439 | 434 |
440 bool HandleScopeImplementer::HasSavedContexts() { | 435 bool HandleScopeImplementer::HasSavedContexts() { |
441 return !saved_contexts_.is_empty(); | 436 return !saved_contexts_.is_empty(); |
442 } | 437 } |
443 | 438 |
444 | 439 |
445 void HandleScopeImplementer::SaveSecurityContext(Handle<Object> context) { | |
446 saved_security_contexts_.Add(context); | |
447 } | |
448 | |
449 | |
450 Handle<Object> HandleScopeImplementer::RestoreSecurityContext() { | |
451 return saved_security_contexts_.RemoveLast(); | |
452 } | |
453 | |
454 | |
455 bool HandleScopeImplementer::HasSavedSecurityContexts() { | |
456 return !saved_security_contexts_.is_empty(); | |
457 } | |
458 | |
459 | |
460 void HandleScopeImplementer::EnterContext(Handle<Object> context) { | 440 void HandleScopeImplementer::EnterContext(Handle<Object> context) { |
461 entered_contexts_.Add(context); | 441 entered_contexts_.Add(context); |
462 } | 442 } |
463 | 443 |
464 | 444 |
465 bool HandleScopeImplementer::LeaveLastContext() { | 445 bool HandleScopeImplementer::LeaveLastContext() { |
466 if (entered_contexts_.is_empty()) return false; | 446 if (entered_contexts_.is_empty()) return false; |
467 entered_contexts_.RemoveLast(); | 447 entered_contexts_.RemoveLast(); |
468 return true; | 448 return true; |
469 } | 449 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 #ifdef DEBUG | 481 #ifdef DEBUG |
502 ImplementationUtilities::ZapHandleRange( | 482 ImplementationUtilities::ZapHandleRange( |
503 reinterpret_cast<void**>(spare), | 483 reinterpret_cast<void**>(spare), |
504 reinterpret_cast<void**>(&spare[kHandleBlockSize])); | 484 reinterpret_cast<void**>(&spare[kHandleBlockSize])); |
505 #endif | 485 #endif |
506 } | 486 } |
507 | 487 |
508 } } // namespace v8::internal | 488 } } // namespace v8::internal |
509 | 489 |
510 #endif // V8_API_H_ | 490 #endif // V8_API_H_ |
OLD | NEW |