OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 class Date; | 116 class Date; |
117 class DeclaredAccessorDescriptor; | 117 class DeclaredAccessorDescriptor; |
118 class External; | 118 class External; |
119 class Function; | 119 class Function; |
120 class FunctionTemplate; | 120 class FunctionTemplate; |
121 class HeapProfiler; | 121 class HeapProfiler; |
122 class ImplementationUtilities; | 122 class ImplementationUtilities; |
123 class Int32; | 123 class Int32; |
124 class Integer; | 124 class Integer; |
125 class Isolate; | 125 class Isolate; |
| 126 class LocalContext; |
126 class Number; | 127 class Number; |
127 class NumberObject; | 128 class NumberObject; |
128 class Object; | 129 class Object; |
129 class ObjectOperationDescriptor; | 130 class ObjectOperationDescriptor; |
130 class ObjectTemplate; | 131 class ObjectTemplate; |
131 class Primitive; | 132 class Primitive; |
132 class RawOperationDescriptor; | 133 class RawOperationDescriptor; |
133 class Signature; | 134 class Signature; |
134 class StackFrame; | 135 class StackFrame; |
135 class StackTrace; | 136 class StackTrace; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 Persistent<Value> object, | 199 Persistent<Value> object, |
199 void* parameter); | 200 void* parameter); |
200 | 201 |
201 // --- Handles --- | 202 // --- Handles --- |
202 | 203 |
203 #define TYPE_CHECK(T, S) \ | 204 #define TYPE_CHECK(T, S) \ |
204 while (false) { \ | 205 while (false) { \ |
205 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | 206 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
206 } | 207 } |
207 | 208 |
| 209 |
| 210 #define V8_USE_UNSAFE_HANDLES |
| 211 |
208 /** | 212 /** |
209 * An object reference managed by the v8 garbage collector. | 213 * An object reference managed by the v8 garbage collector. |
210 * | 214 * |
211 * All objects returned from v8 have to be tracked by the garbage | 215 * All objects returned from v8 have to be tracked by the garbage |
212 * collector so that it knows that the objects are still alive. Also, | 216 * collector so that it knows that the objects are still alive. Also, |
213 * because the garbage collector may move objects, it is unsafe to | 217 * because the garbage collector may move objects, it is unsafe to |
214 * point directly to an object. Instead, all objects are stored in | 218 * point directly to an object. Instead, all objects are stored in |
215 * handles which are known by the garbage collector and updated | 219 * handles which are known by the garbage collector and updated |
216 * whenever an object moves. Handles should always be passed by value | 220 * whenever an object moves. Handles should always be passed by value |
217 * (except in cases like out-parameters) and they should never be | 221 * (except in cases like out-parameters) and they should never be |
(...skipping 12 matching lines...) Expand all Loading... |
230 * behind the scenes and the same rules apply to these values as to | 234 * behind the scenes and the same rules apply to these values as to |
231 * their handles. | 235 * their handles. |
232 */ | 236 */ |
233 template <class T> class Handle { | 237 template <class T> class Handle { |
234 public: | 238 public: |
235 /** | 239 /** |
236 * Creates an empty handle. | 240 * Creates an empty handle. |
237 */ | 241 */ |
238 V8_INLINE(Handle()) : val_(0) {} | 242 V8_INLINE(Handle()) : val_(0) {} |
239 | 243 |
| 244 #ifdef V8_USE_UNSAFE_HANDLES |
240 /** | 245 /** |
241 * Creates a new handle for the specified value. | 246 * Creates a new handle for the specified value. |
242 */ | 247 */ |
243 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | 248 V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 249 #endif |
244 | 250 |
245 /** | 251 /** |
246 * Creates a handle for the contents of the specified handle. This | 252 * Creates a handle for the contents of the specified handle. This |
247 * constructor allows you to pass handles as arguments by value and | 253 * constructor allows you to pass handles as arguments by value and |
248 * to assign between handles. However, if you try to assign between | 254 * to assign between handles. However, if you try to assign between |
249 * incompatible handles, for instance from a Handle<String> to a | 255 * incompatible handles, for instance from a Handle<String> to a |
250 * Handle<Number> it will cause a compile-time error. Assigning | 256 * Handle<Number> it will cause a compile-time error. Assigning |
251 * between compatible handles, for instance assigning a | 257 * between compatible handles, for instance assigning a |
252 * Handle<String> to a variable declared as Handle<Value>, is legal | 258 * Handle<String> to a variable declared as Handle<Value>, is legal |
253 * because String is a subclass of Value. | 259 * because String is a subclass of Value. |
(...skipping 21 matching lines...) Expand all Loading... |
275 V8_INLINE(T* operator->() const) { return val_; } | 281 V8_INLINE(T* operator->() const) { return val_; } |
276 | 282 |
277 V8_INLINE(T* operator*() const) { return val_; } | 283 V8_INLINE(T* operator*() const) { return val_; } |
278 | 284 |
279 /** | 285 /** |
280 * Checks whether two handles are the same. | 286 * Checks whether two handles are the same. |
281 * Returns true if both are empty, or if the objects | 287 * Returns true if both are empty, or if the objects |
282 * to which they refer are identical. | 288 * to which they refer are identical. |
283 * The handles' references are not checked. | 289 * The handles' references are not checked. |
284 */ | 290 */ |
285 template <class S> V8_INLINE(bool operator==(Handle<S> that) const) { | 291 template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
286 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 292 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
287 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 293 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
288 if (a == 0) return b == 0; | 294 if (a == 0) return b == 0; |
289 if (b == 0) return false; | 295 if (b == 0) return false; |
290 return *a == *b; | 296 return *a == *b; |
291 } | 297 } |
292 | 298 |
| 299 #ifndef V8_USE_UNSAFE_HANDLES |
| 300 template <class S> V8_INLINE( |
| 301 bool operator==(const Persistent<S>& that) const) { |
| 302 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 303 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 304 if (a == 0) return b == 0; |
| 305 if (b == 0) return false; |
| 306 return *a == *b; |
| 307 } |
| 308 #endif |
| 309 |
293 /** | 310 /** |
294 * Checks whether two handles are different. | 311 * Checks whether two handles are different. |
295 * Returns true if only one of the handles is empty, or if | 312 * Returns true if only one of the handles is empty, or if |
296 * the objects to which they refer are different. | 313 * the objects to which they refer are different. |
297 * The handles' references are not checked. | 314 * The handles' references are not checked. |
298 */ | 315 */ |
299 template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { | 316 template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
300 return !operator==(that); | 317 return !operator==(that); |
301 } | 318 } |
302 | 319 |
303 template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) { | 320 template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) { |
304 #ifdef V8_ENABLE_CHECKS | 321 #ifdef V8_ENABLE_CHECKS |
305 // If we're going to perform the type check then we have to check | 322 // If we're going to perform the type check then we have to check |
306 // that the handle isn't empty before doing the checked cast. | 323 // that the handle isn't empty before doing the checked cast. |
307 if (that.IsEmpty()) return Handle<T>(); | 324 if (that.IsEmpty()) return Handle<T>(); |
308 #endif | 325 #endif |
309 return Handle<T>(T::Cast(*that)); | 326 return Handle<T>(T::Cast(*that)); |
310 } | 327 } |
311 | 328 |
312 template <class S> V8_INLINE(Handle<S> As()) { | 329 template <class S> V8_INLINE(Handle<S> As()) { |
313 return Handle<S>::Cast(*this); | 330 return Handle<S>::Cast(*this); |
314 } | 331 } |
315 | 332 |
| 333 #ifndef V8_USE_UNSAFE_HANDLES |
| 334 V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 335 return New(isolate, that.val_); |
| 336 } |
| 337 // TODO(dcarney): remove before cutover |
| 338 V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 339 return New(isolate, that.val_); |
| 340 } |
| 341 |
| 342 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 343 |
316 private: | 344 private: |
| 345 #endif |
| 346 /** |
| 347 * Creates a new handle for the specified value. |
| 348 */ |
| 349 V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 350 #endif |
| 351 |
| 352 private: |
| 353 template<class F> |
| 354 friend class Persistent; |
| 355 template<class F> |
| 356 friend class Local; |
| 357 friend class Arguments; |
| 358 friend class String; |
| 359 friend class Object; |
| 360 friend class AccessorInfo; |
| 361 friend Handle<Primitive> Undefined(Isolate* isolate); |
| 362 friend Handle<Primitive> Null(Isolate* isolate); |
| 363 friend Handle<Boolean> True(Isolate* isolate); |
| 364 friend Handle<Boolean> False(Isolate* isolate); |
| 365 friend class Context; |
| 366 friend class InternalHandleHelper; |
| 367 friend class LocalContext; |
| 368 |
| 369 #ifndef V8_USE_UNSAFE_HANDLES |
| 370 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 371 #endif |
| 372 |
317 T* val_; | 373 T* val_; |
318 }; | 374 }; |
319 | 375 |
320 | 376 |
321 /** | 377 /** |
322 * A light-weight stack-allocated object handle. All operations | 378 * A light-weight stack-allocated object handle. All operations |
323 * that return objects from within v8 return them in local handles. They | 379 * that return objects from within v8 return them in local handles. They |
324 * are created within HandleScopes, and all local handles allocated within a | 380 * are created within HandleScopes, and all local handles allocated within a |
325 * handle scope are destroyed when the handle scope is destroyed. Hence it | 381 * handle scope are destroyed when the handle scope is destroyed. Hence it |
326 * is not necessary to explicitly deallocate local handles. | 382 * is not necessary to explicitly deallocate local handles. |
327 */ | 383 */ |
| 384 // TODO(dcarney): deprecate entire class |
328 template <class T> class Local : public Handle<T> { | 385 template <class T> class Local : public Handle<T> { |
329 public: | 386 public: |
330 V8_INLINE(Local()); | 387 V8_INLINE(Local()); |
331 template <class S> V8_INLINE(Local(Local<S> that)) | 388 template <class S> V8_INLINE(Local(Local<S> that)) |
332 : Handle<T>(reinterpret_cast<T*>(*that)) { | 389 : Handle<T>(reinterpret_cast<T*>(*that)) { |
333 /** | 390 /** |
334 * This check fails when trying to convert between incompatible | 391 * This check fails when trying to convert between incompatible |
335 * handles. For example, converting from a Handle<String> to a | 392 * handles. For example, converting from a Handle<String> to a |
336 * Handle<Number>. | 393 * Handle<Number>. |
337 */ | 394 */ |
338 TYPE_CHECK(T, S); | 395 TYPE_CHECK(T, S); |
339 } | 396 } |
| 397 |
| 398 |
| 399 #ifdef V8_USE_UNSAFE_HANDLES |
340 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | 400 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 401 #endif |
| 402 |
341 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { | 403 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { |
342 #ifdef V8_ENABLE_CHECKS | 404 #ifdef V8_ENABLE_CHECKS |
343 // If we're going to perform the type check then we have to check | 405 // If we're going to perform the type check then we have to check |
344 // that the handle isn't empty before doing the checked cast. | 406 // that the handle isn't empty before doing the checked cast. |
345 if (that.IsEmpty()) return Local<T>(); | 407 if (that.IsEmpty()) return Local<T>(); |
346 #endif | 408 #endif |
347 return Local<T>(T::Cast(*that)); | 409 return Local<T>(T::Cast(*that)); |
348 } | 410 } |
| 411 #ifndef V8_USE_UNSAFE_HANDLES |
| 412 template <class S> V8_INLINE(Local(Handle<S> that)) |
| 413 : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 414 TYPE_CHECK(T, S); |
| 415 } |
| 416 #endif |
349 | 417 |
350 template <class S> V8_INLINE(Local<S> As()) { | 418 template <class S> V8_INLINE(Local<S> As()) { |
351 return Local<S>::Cast(*this); | 419 return Local<S>::Cast(*this); |
352 } | 420 } |
353 | 421 |
354 /** | 422 /** |
355 * Create a local handle for the content of another handle. | 423 * Create a local handle for the content of another handle. |
356 * The referee is kept alive by the local handle even when | 424 * The referee is kept alive by the local handle even when |
357 * the original handle is destroyed/disposed. | 425 * the original handle is destroyed/disposed. |
358 */ | 426 */ |
359 V8_INLINE(static Local<T> New(Handle<T> that)); | 427 V8_INLINE(static Local<T> New(Handle<T> that)); |
360 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); | 428 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
| 429 #ifndef V8_USE_UNSAFE_HANDLES |
| 430 // TODO(dcarney): remove before cutover |
| 431 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
| 432 |
| 433 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 434 |
| 435 private: |
| 436 #endif |
| 437 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 438 #endif |
| 439 |
| 440 private: |
| 441 template<class F> |
| 442 friend class Persistent; |
| 443 template<class F> |
| 444 friend class Handle; |
| 445 friend class Arguments; |
| 446 friend class String; |
| 447 friend class Object; |
| 448 friend class AccessorInfo; |
| 449 friend class Context; |
| 450 friend class InternalHandleHelper; |
| 451 friend class LocalContext; |
| 452 |
| 453 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
361 }; | 454 }; |
362 | 455 |
363 | |
364 /** | 456 /** |
365 * An object reference that is independent of any handle scope. Where | 457 * An object reference that is independent of any handle scope. Where |
366 * a Local handle only lives as long as the HandleScope in which it was | 458 * a Local handle only lives as long as the HandleScope in which it was |
367 * allocated, a Persistent handle remains valid until it is explicitly | 459 * allocated, a Persistent handle remains valid until it is explicitly |
368 * disposed. | 460 * disposed. |
369 * | 461 * |
370 * A persistent handle contains a reference to a storage cell within | 462 * A persistent handle contains a reference to a storage cell within |
371 * the v8 engine which holds an object value and which is updated by | 463 * the v8 engine which holds an object value and which is updated by |
372 * the garbage collector whenever the object is moved. A new storage | 464 * the garbage collector whenever the object is moved. A new storage |
373 * cell can be created using Persistent::New and existing handles can | 465 * cell can be created using Persistent::New and existing handles can |
374 * be disposed using Persistent::Dispose. Since persistent handles | 466 * be disposed using Persistent::Dispose. Since persistent handles |
375 * are passed by value you may have many persistent handle objects | 467 * are passed by value you may have many persistent handle objects |
376 * that point to the same storage cell. For instance, if you pass a | 468 * that point to the same storage cell. For instance, if you pass a |
377 * persistent handle as an argument to a function you will not get two | 469 * persistent handle as an argument to a function you will not get two |
378 * different storage cells but rather two references to the same | 470 * different storage cells but rather two references to the same |
379 * storage cell. | 471 * storage cell. |
380 */ | 472 */ |
381 template <class T> class Persistent : public Handle<T> { | 473 template <class T> class Persistent // NOLINT |
| 474 #ifdef V8_USE_UNSAFE_HANDLES |
| 475 : public Handle<T> { |
| 476 #else |
| 477 { // NOLINT |
| 478 #endif |
382 public: | 479 public: |
| 480 #ifndef V8_USE_UNSAFE_HANDLES |
| 481 V8_INLINE(Persistent()) : val_(0) { } |
| 482 V8_INLINE(~Persistent()) { |
| 483 // TODO(dcarney): add this back before cutover. |
| 484 // Dispose(); |
| 485 } |
| 486 V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 487 // TODO(dcarney): remove somehow before cutover |
| 488 // The handle should either be 0, or a pointer to a live cell. |
| 489 V8_INLINE(void Clear()) { val_ = 0; } |
| 490 |
| 491 /** |
| 492 * A constructor that creates a new global cell pointing to that. In contrast |
| 493 * to the copy constructor, this creates a new persistent handle which needs |
| 494 * to be separately disposed. |
| 495 */ |
| 496 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 497 : val_(*New(isolate, that)) { } |
| 498 |
| 499 #else |
383 /** | 500 /** |
384 * Creates an empty persistent handle that doesn't point to any | 501 * Creates an empty persistent handle that doesn't point to any |
385 * storage cell. | 502 * storage cell. |
386 */ | 503 */ |
387 V8_INLINE(Persistent()); | 504 V8_INLINE(Persistent()) : Handle<T>() { } |
388 | 505 |
389 /** | 506 /** |
390 * Creates a persistent handle for the same storage cell as the | 507 * Creates a persistent handle for the same storage cell as the |
391 * specified handle. This constructor allows you to pass persistent | 508 * specified handle. This constructor allows you to pass persistent |
392 * handles as arguments by value and to assign between persistent | 509 * handles as arguments by value and to assign between persistent |
393 * handles. However, attempting to assign between incompatible | 510 * handles. However, attempting to assign between incompatible |
394 * persistent handles, for instance from a Persistent<String> to a | 511 * persistent handles, for instance from a Persistent<String> to a |
395 * Persistent<Number> will cause a compile-time error. Assigning | 512 * Persistent<Number> will cause a compile-time error. Assigning |
396 * between compatible persistent handles, for instance assigning a | 513 * between compatible persistent handles, for instance assigning a |
397 * Persistent<String> to a variable declared as Persistent<Value>, | 514 * Persistent<String> to a variable declared as Persistent<Value>, |
(...skipping 19 matching lines...) Expand all Loading... |
417 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) | 534 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
418 : Handle<T>(New(isolate, that)) { } | 535 : Handle<T>(New(isolate, that)) { } |
419 | 536 |
420 /** | 537 /** |
421 * "Casts" a plain handle which is known to be a persistent handle | 538 * "Casts" a plain handle which is known to be a persistent handle |
422 * to a persistent handle. | 539 * to a persistent handle. |
423 */ | 540 */ |
424 template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) | 541 template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
425 : Handle<T>(*that) { } | 542 : Handle<T>(*that) { } |
426 | 543 |
| 544 #endif |
| 545 |
427 template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { | 546 template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { |
428 #ifdef V8_ENABLE_CHECKS | 547 #ifdef V8_ENABLE_CHECKS |
429 // If we're going to perform the type check then we have to check | 548 // If we're going to perform the type check then we have to check |
430 // that the handle isn't empty before doing the checked cast. | 549 // that the handle isn't empty before doing the checked cast. |
431 if (that.IsEmpty()) return Persistent<T>(); | 550 if (that.IsEmpty()) return Persistent<T>(); |
432 #endif | 551 #endif |
433 return Persistent<T>(T::Cast(*that)); | 552 return Persistent<T>(T::Cast(*that)); |
434 } | 553 } |
435 | 554 |
436 template <class S> V8_INLINE(Persistent<S> As()) { | 555 template <class S> V8_INLINE(Persistent<S> As()) { |
437 return Persistent<S>::Cast(*this); | 556 return Persistent<S>::Cast(*this); |
438 } | 557 } |
439 | 558 |
440 /** Deprecated. Use Isolate version instead. */ | |
441 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); | 559 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
442 | 560 |
443 /** | 561 /** |
444 * Creates a new persistent handle for an existing local or persistent handle. | 562 * Creates a new persistent handle for an existing local or persistent handle. |
445 */ | 563 */ |
| 564 // TODO(dcarney): remove before cutover |
446 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); | 565 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
| 566 #ifndef V8_USE_UNSAFE_HANDLES |
| 567 // TODO(dcarney): remove before cutover |
| 568 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 569 #endif |
447 | 570 |
448 /** Deprecated. Use Isolate version instead. */ | 571 #ifndef V8_USE_UNSAFE_HANDLES |
449 V8_DEPRECATED(void Dispose()); | 572 template <class S> V8_INLINE( |
| 573 bool operator==(const Persistent<S>& that) const) { |
| 574 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 575 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 576 if (a == 0) return b == 0; |
| 577 if (b == 0) return false; |
| 578 return *a == *b; |
| 579 } |
| 580 |
| 581 template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 582 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 583 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 584 if (a == 0) return b == 0; |
| 585 if (b == 0) return false; |
| 586 return *a == *b; |
| 587 } |
| 588 #endif |
| 589 |
| 590 V8_INLINE(void Dispose()); |
450 | 591 |
451 /** | 592 /** |
452 * Releases the storage cell referenced by this persistent handle. | 593 * Releases the storage cell referenced by this persistent handle. |
453 * Does not remove the reference to the cell from any handles. | 594 * Does not remove the reference to the cell from any handles. |
454 * This handle's reference, and any other references to the storage | 595 * This handle's reference, and any other references to the storage |
455 * cell remain and IsEmpty will still return false. | 596 * cell remain and IsEmpty will still return false. |
456 */ | 597 */ |
| 598 // TODO(dcarney): remove before cutover |
457 V8_INLINE(void Dispose(Isolate* isolate)); | 599 V8_INLINE(void Dispose(Isolate* isolate)); |
458 | 600 |
459 /** Deprecated. Use Isolate version instead. */ | 601 V8_INLINE(void MakeWeak(void* parameters, |
460 V8_DEPRECATED(void MakeWeak(void* parameters, | |
461 WeakReferenceCallback callback)); | 602 WeakReferenceCallback callback)); |
462 | 603 |
463 /** | 604 /** |
464 * Make the reference to this object weak. When only weak handles | 605 * Make the reference to this object weak. When only weak handles |
465 * refer to the object, the garbage collector will perform a | 606 * refer to the object, the garbage collector will perform a |
466 * callback to the given V8::NearDeathCallback function, passing | 607 * callback to the given V8::NearDeathCallback function, passing |
467 * it the object reference and the given parameters. | 608 * it the object reference and the given parameters. |
468 */ | 609 */ |
| 610 // TODO(dcarney): remove before cutover |
469 V8_INLINE(void MakeWeak(Isolate* isolate, | 611 V8_INLINE(void MakeWeak(Isolate* isolate, |
470 void* parameters, | 612 void* parameters, |
471 NearDeathCallback callback)); | 613 NearDeathCallback callback)); |
472 | 614 |
473 /** Deprecated. Use Isolate version instead. */ | 615 V8_INLINE(void ClearWeak()); |
474 V8_DEPRECATED(void ClearWeak()); | |
475 | 616 |
476 /** Clears the weak reference to this object. */ | 617 // TODO(dcarney): remove before cutover |
477 V8_INLINE(void ClearWeak(Isolate* isolate)); | 618 V8_INLINE(void ClearWeak(Isolate* isolate)); |
478 | 619 |
479 /** Deprecated. Use Isolate version instead. */ | 620 V8_INLINE(void MarkIndependent()); |
480 V8_DEPRECATED(void MarkIndependent()); | |
481 | 621 |
482 /** | 622 /** |
483 * Marks the reference to this object independent. Garbage collector is free | 623 * Marks the reference to this object independent. Garbage collector is free |
484 * to ignore any object groups containing this object. Weak callback for an | 624 * to ignore any object groups containing this object. Weak callback for an |
485 * independent handle should not assume that it will be preceded by a global | 625 * independent handle should not assume that it will be preceded by a global |
486 * GC prologue callback or followed by a global GC epilogue callback. | 626 * GC prologue callback or followed by a global GC epilogue callback. |
487 */ | 627 */ |
| 628 // TODO(dcarney): remove before cutover |
488 V8_INLINE(void MarkIndependent(Isolate* isolate)); | 629 V8_INLINE(void MarkIndependent(Isolate* isolate)); |
489 | 630 |
490 /** Deprecated. Use Isolate version instead. */ | 631 V8_INLINE(void MarkPartiallyDependent()); |
491 V8_DEPRECATED(void MarkPartiallyDependent()); | |
492 | 632 |
493 /** | 633 /** |
494 * Marks the reference to this object partially dependent. Partially dependent | 634 * Marks the reference to this object partially dependent. Partially dependent |
495 * handles only depend on other partially dependent handles and these | 635 * handles only depend on other partially dependent handles and these |
496 * dependencies are provided through object groups. It provides a way to build | 636 * dependencies are provided through object groups. It provides a way to build |
497 * smaller object groups for young objects that represent only a subset of all | 637 * smaller object groups for young objects that represent only a subset of all |
498 * external dependencies. This mark is automatically cleared after each | 638 * external dependencies. This mark is automatically cleared after each |
499 * garbage collection. | 639 * garbage collection. |
500 */ | 640 */ |
| 641 // TODO(dcarney): remove before cutover |
501 V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); | 642 V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
502 | 643 |
503 /** Deprecated. Use Isolate version instead. */ | 644 V8_INLINE(bool IsIndependent() const); |
504 V8_DEPRECATED(bool IsIndependent() const); | |
505 | 645 |
506 /** Returns true if this handle was previously marked as independent. */ | 646 // TODO(dcarney): remove before cutover |
507 V8_INLINE(bool IsIndependent(Isolate* isolate) const); | 647 V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
508 | 648 |
509 /** Deprecated. Use Isolate version instead. */ | 649 V8_INLINE(bool IsNearDeath() const); |
510 V8_DEPRECATED(bool IsNearDeath() const); | |
511 | 650 |
512 /** Checks if the handle holds the only reference to an object. */ | 651 /** Checks if the handle holds the only reference to an object. */ |
| 652 // TODO(dcarney): remove before cutover |
513 V8_INLINE(bool IsNearDeath(Isolate* isolate) const); | 653 V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
514 | 654 |
515 /** Deprecated. Use Isolate version instead. */ | 655 V8_INLINE(bool IsWeak() const); |
516 V8_DEPRECATED(bool IsWeak() const); | |
517 | 656 |
518 /** Returns true if the handle's reference is weak. */ | 657 /** Returns true if the handle's reference is weak. */ |
| 658 // TODO(dcarney): remove before cutover |
519 V8_INLINE(bool IsWeak(Isolate* isolate) const); | 659 V8_INLINE(bool IsWeak(Isolate* isolate) const); |
520 | 660 |
521 /** Deprecated. Use Isolate version instead. */ | 661 V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
522 V8_DEPRECATED(void SetWrapperClassId(uint16_t class_id)); | |
523 | 662 |
524 /** | 663 /** |
525 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface | 664 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
526 * description in v8-profiler.h for details. | 665 * description in v8-profiler.h for details. |
527 */ | 666 */ |
| 667 // TODO(dcarney): remove before cutover |
528 V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); | 668 V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
529 | 669 |
530 /** Deprecated. Use Isolate version instead. */ | 670 V8_INLINE(uint16_t WrapperClassId() const); |
531 V8_DEPRECATED(uint16_t WrapperClassId() const); | |
532 | 671 |
533 /** | 672 /** |
534 * Returns the class ID previously assigned to this handle or 0 if no class ID | 673 * Returns the class ID previously assigned to this handle or 0 if no class ID |
535 * was previously assigned. | 674 * was previously assigned. |
536 */ | 675 */ |
| 676 // TODO(dcarney): remove before cutover |
537 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); | 677 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
538 | 678 |
| 679 #ifndef V8_USE_UNSAFE_HANDLES |
| 680 |
| 681 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 682 |
539 private: | 683 private: |
| 684 #endif |
| 685 // TODO(dcarney): make unlinkable before cutover |
| 686 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 687 // TODO(dcarney): make unlinkable before cutover |
| 688 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 689 this->val_ = that.val_; |
| 690 return *this; |
| 691 } |
| 692 |
| 693 public: |
| 694 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 695 |
| 696 private: |
| 697 #endif |
| 698 // TODO(dcarney): remove before cutover |
| 699 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 700 // TODO(dcarney): remove before cutover |
| 701 template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| 702 : val_(*that) { |
| 703 TYPE_CHECK(T, S); |
| 704 } |
| 705 // TODO(dcarney): remove before cutover |
| 706 V8_INLINE(T* operator*() const) { return val_; } |
| 707 public: |
| 708 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 709 |
| 710 private: |
| 711 #endif |
| 712 // TODO(dcarney): remove before cutover |
| 713 V8_INLINE(T* operator->() const) { return val_; } |
| 714 public: |
| 715 #endif |
| 716 |
| 717 private: |
| 718 template<class F> |
| 719 friend class Handle; |
| 720 template<class F> |
| 721 friend class Local; |
540 friend class ImplementationUtilities; | 722 friend class ImplementationUtilities; |
541 friend class ObjectTemplate; | 723 friend class ObjectTemplate; |
| 724 friend class Context; |
| 725 friend class InternalHandleHelper; |
| 726 friend class LocalContext; |
| 727 |
| 728 V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
| 729 |
| 730 #ifndef V8_USE_UNSAFE_HANDLES |
| 731 T* val_; |
| 732 #endif |
542 }; | 733 }; |
543 | 734 |
544 | 735 |
545 /** | 736 /** |
546 * A stack-allocated class that governs a number of local handles. | 737 * A stack-allocated class that governs a number of local handles. |
547 * After a handle scope has been created, all local handles will be | 738 * After a handle scope has been created, all local handles will be |
548 * allocated within that handle scope until either the handle scope is | 739 * allocated within that handle scope until either the handle scope is |
549 * deleted or another handle scope is created. If there is already a | 740 * deleted or another handle scope is created. If there is already a |
550 * handle scope and a new one is created, all allocations will take | 741 * handle scope and a new one is created, all allocations will take |
551 * place in the new handle scope until it is deleted. After that, | 742 * place in the new handle scope until it is deleted. After that, |
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4413 | 4604 |
4414 /** | 4605 /** |
4415 * Stack-allocated class which sets the execution context for all | 4606 * Stack-allocated class which sets the execution context for all |
4416 * operations executed within a local scope. | 4607 * operations executed within a local scope. |
4417 */ | 4608 */ |
4418 class Scope { | 4609 class Scope { |
4419 public: | 4610 public: |
4420 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { | 4611 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
4421 context_->Enter(); | 4612 context_->Enter(); |
4422 } | 4613 } |
| 4614 V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4615 #ifndef V8_USE_UNSAFE_HANDLES |
| 4616 : context_(Handle<Context>::New(isolate, context)) { |
| 4617 #else |
| 4618 : context_(Local<Context>::New(isolate, context)) { |
| 4619 #endif |
| 4620 context_->Enter(); |
| 4621 } |
4423 V8_INLINE(~Scope()) { context_->Exit(); } | 4622 V8_INLINE(~Scope()) { context_->Exit(); } |
| 4623 |
4424 private: | 4624 private: |
4425 Handle<Context> context_; | 4625 Handle<Context> context_; |
4426 }; | 4626 }; |
4427 | 4627 |
4428 private: | 4628 private: |
4429 friend class Value; | 4629 friend class Value; |
4430 friend class Script; | 4630 friend class Script; |
4431 friend class Object; | 4631 friend class Object; |
4432 friend class Function; | 4632 friend class Function; |
4433 | 4633 |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4852 if (internal::Internals::CanCastToHeapObject(that_ptr)) { | 5052 if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
4853 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 5053 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
4854 reinterpret_cast<internal::HeapObject*>(*p)))); | 5054 reinterpret_cast<internal::HeapObject*>(*p)))); |
4855 } | 5055 } |
4856 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | 5056 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
4857 } | 5057 } |
4858 | 5058 |
4859 | 5059 |
4860 template <class T> | 5060 template <class T> |
4861 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | 5061 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
4862 if (that.IsEmpty()) return Local<T>(); | 5062 return New(isolate, that.val_); |
4863 T* that_ptr = *that; | 5063 } |
| 5064 |
| 5065 #ifndef V8_USE_UNSAFE_HANDLES |
| 5066 template <class T> |
| 5067 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5068 return New(isolate, that.val_); |
| 5069 } |
| 5070 |
| 5071 template <class T> |
| 5072 Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5073 if (that == NULL) return Handle<T>(); |
| 5074 T* that_ptr = that; |
| 5075 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5076 return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5077 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5078 } |
| 5079 #endif |
| 5080 |
| 5081 |
| 5082 template <class T> |
| 5083 Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5084 if (that == NULL) return Local<T>(); |
| 5085 T* that_ptr = that; |
4864 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 5086 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
4865 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 5087 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
4866 reinterpret_cast<internal::Isolate*>(isolate), *p))); | 5088 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
4867 } | 5089 } |
4868 | 5090 |
4869 | 5091 |
4870 template <class T> | 5092 template <class T> |
4871 Persistent<T> Persistent<T>::New(Handle<T> that) { | 5093 Persistent<T> Persistent<T>::New(Handle<T> that) { |
4872 return New(Isolate::GetCurrent(), that); | 5094 return New(Isolate::GetCurrent(), that.val_); |
4873 } | 5095 } |
4874 | 5096 |
4875 | 5097 |
4876 template <class T> | 5098 template <class T> |
4877 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { | 5099 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
4878 if (that.IsEmpty()) return Persistent<T>(); | 5100 return New(Isolate::GetCurrent(), that.val_); |
4879 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 5101 } |
| 5102 |
| 5103 #ifndef V8_USE_UNSAFE_HANDLES |
| 5104 template <class T> |
| 5105 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5106 return New(Isolate::GetCurrent(), that.val_); |
| 5107 } |
| 5108 #endif |
| 5109 |
| 5110 template <class T> |
| 5111 Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { |
| 5112 if (that == NULL) return Persistent<T>(); |
| 5113 internal::Object** p = reinterpret_cast<internal::Object**>(that); |
4880 return Persistent<T>(reinterpret_cast<T*>( | 5114 return Persistent<T>(reinterpret_cast<T*>( |
4881 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | 5115 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
4882 p))); | 5116 p))); |
4883 } | 5117 } |
4884 | 5118 |
4885 | 5119 |
4886 template <class T> | 5120 template <class T> |
4887 bool Persistent<T>::IsIndependent() const { | 5121 bool Persistent<T>::IsIndependent() const { |
4888 return IsIndependent(Isolate::GetCurrent()); | 5122 return IsIndependent(Isolate::GetCurrent()); |
4889 } | 5123 } |
4890 | 5124 |
4891 | 5125 |
4892 template <class T> | 5126 template <class T> |
4893 bool Persistent<T>::IsIndependent(Isolate* isolate) const { | 5127 bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
4894 typedef internal::Internals I; | 5128 typedef internal::Internals I; |
4895 if (this->IsEmpty()) return false; | 5129 if (this->IsEmpty()) return false; |
4896 if (!I::IsInitialized(isolate)) return false; | 5130 if (!I::IsInitialized(isolate)) return false; |
4897 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(**this), | 5131 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
4898 I::kNodeIsIndependentShift); | 5132 I::kNodeIsIndependentShift); |
4899 } | 5133 } |
4900 | 5134 |
4901 | 5135 |
4902 template <class T> | 5136 template <class T> |
4903 bool Persistent<T>::IsNearDeath() const { | 5137 bool Persistent<T>::IsNearDeath() const { |
4904 return IsNearDeath(Isolate::GetCurrent()); | 5138 return IsNearDeath(Isolate::GetCurrent()); |
4905 } | 5139 } |
4906 | 5140 |
4907 | 5141 |
4908 template <class T> | 5142 template <class T> |
4909 bool Persistent<T>::IsNearDeath(Isolate* isolate) const { | 5143 bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
4910 typedef internal::Internals I; | 5144 typedef internal::Internals I; |
4911 if (this->IsEmpty()) return false; | 5145 if (this->IsEmpty()) return false; |
4912 if (!I::IsInitialized(isolate)) return false; | 5146 if (!I::IsInitialized(isolate)) return false; |
4913 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) == | 5147 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
4914 I::kNodeStateIsNearDeathValue; | 5148 I::kNodeStateIsNearDeathValue; |
4915 } | 5149 } |
4916 | 5150 |
4917 | 5151 |
4918 template <class T> | 5152 template <class T> |
4919 bool Persistent<T>::IsWeak() const { | 5153 bool Persistent<T>::IsWeak() const { |
4920 return IsWeak(Isolate::GetCurrent()); | 5154 return IsWeak(Isolate::GetCurrent()); |
4921 } | 5155 } |
4922 | 5156 |
4923 | 5157 |
4924 template <class T> | 5158 template <class T> |
4925 bool Persistent<T>::IsWeak(Isolate* isolate) const { | 5159 bool Persistent<T>::IsWeak(Isolate* isolate) const { |
4926 typedef internal::Internals I; | 5160 typedef internal::Internals I; |
4927 if (this->IsEmpty()) return false; | 5161 if (this->IsEmpty()) return false; |
4928 if (!I::IsInitialized(isolate)) return false; | 5162 if (!I::IsInitialized(isolate)) return false; |
4929 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) == | 5163 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
4930 I::kNodeStateIsWeakValue; | 5164 I::kNodeStateIsWeakValue; |
4931 } | 5165 } |
4932 | 5166 |
4933 | 5167 |
4934 template <class T> | 5168 template <class T> |
4935 void Persistent<T>::Dispose() { | 5169 void Persistent<T>::Dispose() { |
4936 Dispose(Isolate::GetCurrent()); | 5170 Dispose(Isolate::GetCurrent()); |
4937 } | 5171 } |
4938 | 5172 |
4939 | 5173 |
4940 template <class T> | 5174 template <class T> |
4941 void Persistent<T>::Dispose(Isolate* isolate) { | 5175 void Persistent<T>::Dispose(Isolate* isolate) { |
4942 if (this->IsEmpty()) return; | 5176 if (this->IsEmpty()) return; |
4943 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), | 5177 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), |
4944 reinterpret_cast<internal::Object**>(**this)); | 5178 reinterpret_cast<internal::Object**>(this->val_)); |
| 5179 #ifndef V8_USE_UNSAFE_HANDLES |
| 5180 val_ = 0; |
| 5181 #endif |
4945 } | 5182 } |
4946 | 5183 |
4947 | 5184 |
4948 template <class T> | 5185 template <class T> |
4949 Persistent<T>::Persistent() : Handle<T>() { } | |
4950 | |
4951 template <class T> | |
4952 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { | 5186 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { |
4953 Isolate* isolate = Isolate::GetCurrent(); | 5187 Isolate* isolate = Isolate::GetCurrent(); |
4954 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | 5188 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
4955 reinterpret_cast<internal::Object**>(**this), | 5189 reinterpret_cast<internal::Object**>(this->val_), |
4956 parameters, | 5190 parameters, |
4957 callback, | 5191 callback, |
4958 NULL); | 5192 NULL); |
4959 } | 5193 } |
4960 | 5194 |
4961 template <class T> | 5195 template <class T> |
4962 void Persistent<T>::MakeWeak(Isolate* isolate, | 5196 void Persistent<T>::MakeWeak(Isolate* isolate, |
4963 void* parameters, | 5197 void* parameters, |
4964 NearDeathCallback callback) { | 5198 NearDeathCallback callback) { |
4965 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | 5199 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
4966 reinterpret_cast<internal::Object**>(**this), | 5200 reinterpret_cast<internal::Object**>(this->val_), |
4967 parameters, | 5201 parameters, |
4968 NULL, | 5202 NULL, |
4969 callback); | 5203 callback); |
4970 } | 5204 } |
4971 | 5205 |
4972 template <class T> | 5206 template <class T> |
4973 void Persistent<T>::ClearWeak() { | 5207 void Persistent<T>::ClearWeak() { |
4974 ClearWeak(Isolate::GetCurrent()); | 5208 ClearWeak(Isolate::GetCurrent()); |
4975 } | 5209 } |
4976 | 5210 |
4977 template <class T> | 5211 template <class T> |
4978 void Persistent<T>::ClearWeak(Isolate* isolate) { | 5212 void Persistent<T>::ClearWeak(Isolate* isolate) { |
4979 V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), | 5213 V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
4980 reinterpret_cast<internal::Object**>(**this)); | 5214 reinterpret_cast<internal::Object**>(this->val_)); |
4981 } | 5215 } |
4982 | 5216 |
4983 template <class T> | 5217 template <class T> |
4984 void Persistent<T>::MarkIndependent() { | 5218 void Persistent<T>::MarkIndependent() { |
4985 MarkIndependent(Isolate::GetCurrent()); | 5219 MarkIndependent(Isolate::GetCurrent()); |
4986 } | 5220 } |
4987 | 5221 |
4988 template <class T> | 5222 template <class T> |
4989 void Persistent<T>::MarkIndependent(Isolate* isolate) { | 5223 void Persistent<T>::MarkIndependent(Isolate* isolate) { |
4990 typedef internal::Internals I; | 5224 typedef internal::Internals I; |
4991 if (this->IsEmpty()) return; | 5225 if (this->IsEmpty()) return; |
4992 if (!I::IsInitialized(isolate)) return; | 5226 if (!I::IsInitialized(isolate)) return; |
4993 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this), | 5227 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
4994 true, | 5228 true, |
4995 I::kNodeIsIndependentShift); | 5229 I::kNodeIsIndependentShift); |
4996 } | 5230 } |
4997 | 5231 |
4998 template <class T> | 5232 template <class T> |
4999 void Persistent<T>::MarkPartiallyDependent() { | 5233 void Persistent<T>::MarkPartiallyDependent() { |
5000 MarkPartiallyDependent(Isolate::GetCurrent()); | 5234 MarkPartiallyDependent(Isolate::GetCurrent()); |
5001 } | 5235 } |
5002 | 5236 |
5003 template <class T> | 5237 template <class T> |
5004 void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { | 5238 void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
5005 typedef internal::Internals I; | 5239 typedef internal::Internals I; |
5006 if (this->IsEmpty()) return; | 5240 if (this->IsEmpty()) return; |
5007 if (!I::IsInitialized(isolate)) return; | 5241 if (!I::IsInitialized(isolate)) return; |
5008 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this), | 5242 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
5009 true, | 5243 true, |
5010 I::kNodeIsPartiallyDependentShift); | 5244 I::kNodeIsPartiallyDependentShift); |
5011 } | 5245 } |
5012 | 5246 |
5013 template <class T> | 5247 template <class T> |
5014 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | 5248 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
5015 SetWrapperClassId(Isolate::GetCurrent(), class_id); | 5249 SetWrapperClassId(Isolate::GetCurrent(), class_id); |
5016 } | 5250 } |
5017 | 5251 |
5018 template <class T> | 5252 template <class T> |
5019 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { | 5253 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
5020 typedef internal::Internals I; | 5254 typedef internal::Internals I; |
5021 if (this->IsEmpty()) return; | 5255 if (this->IsEmpty()) return; |
5022 if (!I::IsInitialized(isolate)) return; | 5256 if (!I::IsInitialized(isolate)) return; |
5023 internal::Object** obj = reinterpret_cast<internal::Object**>(**this); | 5257 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
5024 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5258 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
5025 *reinterpret_cast<uint16_t*>(addr) = class_id; | 5259 *reinterpret_cast<uint16_t*>(addr) = class_id; |
5026 } | 5260 } |
5027 | 5261 |
5028 template <class T> | 5262 template <class T> |
5029 uint16_t Persistent<T>::WrapperClassId() const { | 5263 uint16_t Persistent<T>::WrapperClassId() const { |
5030 return WrapperClassId(Isolate::GetCurrent()); | 5264 return WrapperClassId(Isolate::GetCurrent()); |
5031 } | 5265 } |
5032 | 5266 |
5033 template <class T> | 5267 template <class T> |
5034 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { | 5268 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
5035 typedef internal::Internals I; | 5269 typedef internal::Internals I; |
5036 if (this->IsEmpty()) return 0; | 5270 if (this->IsEmpty()) return 0; |
5037 if (!I::IsInitialized(isolate)) return 0; | 5271 if (!I::IsInitialized(isolate)) return 0; |
5038 internal::Object** obj = reinterpret_cast<internal::Object**>(**this); | 5272 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
5039 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5273 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
5040 return *reinterpret_cast<uint16_t*>(addr); | 5274 return *reinterpret_cast<uint16_t*>(addr); |
5041 } | 5275 } |
5042 | 5276 |
5043 Arguments::Arguments(internal::Object** implicit_args, | 5277 Arguments::Arguments(internal::Object** implicit_args, |
5044 internal::Object** values, int length, | 5278 internal::Object** values, int length, |
5045 bool is_construct_call) | 5279 bool is_construct_call) |
5046 : implicit_args_(implicit_args), | 5280 : implicit_args_(implicit_args), |
5047 values_(values), | 5281 values_(values), |
5048 length_(length), | 5282 length_(length), |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5579 | 5813 |
5580 | 5814 |
5581 } // namespace v8 | 5815 } // namespace v8 |
5582 | 5816 |
5583 | 5817 |
5584 #undef V8EXPORT | 5818 #undef V8EXPORT |
5585 #undef TYPE_CHECK | 5819 #undef TYPE_CHECK |
5586 | 5820 |
5587 | 5821 |
5588 #endif // V8_H_ | 5822 #endif // V8_H_ |
OLD | NEW |