OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide |
6 * | 6 * |
7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. |
8 * | 8 * |
9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the |
10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 472 |
473 | 473 |
474 static const int kInternalFieldsInWeakCallback = 2; | 474 static const int kInternalFieldsInWeakCallback = 2; |
475 | 475 |
476 | 476 |
477 template <typename T> | 477 template <typename T> |
478 class WeakCallbackInfo { | 478 class WeakCallbackInfo { |
479 public: | 479 public: |
480 typedef void (*Callback)(const WeakCallbackInfo<T>& data); | 480 typedef void (*Callback)(const WeakCallbackInfo<T>& data); |
481 | 481 |
482 WeakCallbackInfo(Isolate* isolate, T* parameter, void* internal_field1, | 482 WeakCallbackInfo(Isolate* isolate, T* parameter, |
483 void* internal_field2) | 483 void* internal_fields[kInternalFieldsInWeakCallback], |
484 : isolate_(isolate), parameter_(parameter) { | 484 Callback* callback) |
485 internal_fields_[0] = internal_field1; | 485 : isolate_(isolate), parameter_(parameter), callback_(callback) { |
486 internal_fields_[1] = internal_field2; | 486 for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) { |
| 487 internal_fields_[i] = internal_fields[i]; |
| 488 } |
487 } | 489 } |
488 | 490 |
489 V8_INLINE Isolate* GetIsolate() const { return isolate_; } | 491 V8_INLINE Isolate* GetIsolate() const { return isolate_; } |
490 V8_INLINE T* GetParameter() const { return parameter_; } | 492 V8_INLINE T* GetParameter() const { return parameter_; } |
491 V8_INLINE void* GetInternalField(int index) const; | 493 V8_INLINE void* GetInternalField(int index) const; |
492 | 494 |
493 V8_INLINE V8_DEPRECATE_SOON("use indexed version", | 495 V8_INLINE V8_DEPRECATE_SOON("use indexed version", |
494 void* GetInternalField1()) const { | 496 void* GetInternalField1()) const { |
495 return internal_fields_[0]; | 497 return internal_fields_[0]; |
496 } | 498 } |
497 V8_INLINE V8_DEPRECATE_SOON("use indexed version", | 499 V8_INLINE V8_DEPRECATE_SOON("use indexed version", |
498 void* GetInternalField2()) const { | 500 void* GetInternalField2()) const { |
499 return internal_fields_[1]; | 501 return internal_fields_[1]; |
500 } | 502 } |
501 | 503 |
| 504 bool IsFirstPass() const { return callback_ != nullptr; } |
| 505 |
| 506 // When first called, the embedder MUST Reset() the Global which triggered the |
| 507 // callback. The Global itself is unusable for anything else. No v8 other api |
| 508 // calls may be called in the first callback. Should additional work be |
| 509 // required, the embedder must set a second pass callback, which will be |
| 510 // called after all the initial callbacks are processed. |
| 511 // Calling SetSecondPassCallback on the second pass will immediately crash. |
| 512 void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } |
| 513 |
502 private: | 514 private: |
503 Isolate* isolate_; | 515 Isolate* isolate_; |
504 T* parameter_; | 516 T* parameter_; |
505 void* internal_fields_[2]; | 517 Callback* callback_; |
| 518 void* internal_fields_[kInternalFieldsInWeakCallback]; |
506 }; | 519 }; |
507 | 520 |
508 | 521 |
509 template <class T, class P> | 522 template <class T, class P> |
510 class WeakCallbackData { | 523 class WeakCallbackData { |
511 public: | 524 public: |
512 typedef void (*Callback)(const WeakCallbackData<T, P>& data); | 525 typedef void (*Callback)(const WeakCallbackData<T, P>& data); |
513 | 526 |
514 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle) | 527 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle) |
515 : isolate_(isolate), parameter_(parameter), handle_(handle) {} | 528 : isolate_(isolate), parameter_(parameter), handle_(handle) {} |
(...skipping 7478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7994 */ | 8007 */ |
7995 | 8008 |
7996 | 8009 |
7997 } // namespace v8 | 8010 } // namespace v8 |
7998 | 8011 |
7999 | 8012 |
8000 #undef TYPE_CHECK | 8013 #undef TYPE_CHECK |
8001 | 8014 |
8002 | 8015 |
8003 #endif // V8_H_ | 8016 #endif // V8_H_ |
OLD | NEW |