Chromium Code Reviews| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 class Date; | 108 class Date; |
| 109 class DeclaredAccessorDescriptor; | 109 class DeclaredAccessorDescriptor; |
| 110 class External; | 110 class External; |
| 111 class Function; | 111 class Function; |
| 112 class FunctionTemplate; | 112 class FunctionTemplate; |
| 113 class HeapProfiler; | 113 class HeapProfiler; |
| 114 class ImplementationUtilities; | 114 class ImplementationUtilities; |
| 115 class Int32; | 115 class Int32; |
| 116 class Integer; | 116 class Integer; |
| 117 class Isolate; | 117 class Isolate; |
| 118 class LocalContext; | |
| 118 class Number; | 119 class Number; |
| 119 class NumberObject; | 120 class NumberObject; |
| 120 class Object; | 121 class Object; |
| 121 class ObjectOperationDescriptor; | 122 class ObjectOperationDescriptor; |
| 122 class ObjectTemplate; | 123 class ObjectTemplate; |
| 123 class Primitive; | 124 class Primitive; |
| 124 class RawOperationDescriptor; | 125 class RawOperationDescriptor; |
| 125 class Signature; | 126 class Signature; |
| 126 class StackFrame; | 127 class StackFrame; |
| 127 class StackTrace; | 128 class StackTrace; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 Persistent<Value> object, | 166 Persistent<Value> object, |
| 166 void* parameter); | 167 void* parameter); |
| 167 | 168 |
| 168 // --- Handles --- | 169 // --- Handles --- |
| 169 | 170 |
| 170 #define TYPE_CHECK(T, S) \ | 171 #define TYPE_CHECK(T, S) \ |
| 171 while (false) { \ | 172 while (false) { \ |
| 172 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | 173 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
| 173 } | 174 } |
| 174 | 175 |
| 176 | |
| 177 #define V8_USE_UNSAFE_HANDLES | |
| 178 | |
| 175 /** | 179 /** |
| 176 * An object reference managed by the v8 garbage collector. | 180 * An object reference managed by the v8 garbage collector. |
| 177 * | 181 * |
| 178 * All objects returned from v8 have to be tracked by the garbage | 182 * All objects returned from v8 have to be tracked by the garbage |
| 179 * collector so that it knows that the objects are still alive. Also, | 183 * collector so that it knows that the objects are still alive. Also, |
| 180 * because the garbage collector may move objects, it is unsafe to | 184 * because the garbage collector may move objects, it is unsafe to |
| 181 * point directly to an object. Instead, all objects are stored in | 185 * point directly to an object. Instead, all objects are stored in |
| 182 * handles which are known by the garbage collector and updated | 186 * handles which are known by the garbage collector and updated |
| 183 * whenever an object moves. Handles should always be passed by value | 187 * whenever an object moves. Handles should always be passed by value |
| 184 * (except in cases like out-parameters) and they should never be | 188 * (except in cases like out-parameters) and they should never be |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 197 * behind the scenes and the same rules apply to these values as to | 201 * behind the scenes and the same rules apply to these values as to |
| 198 * their handles. | 202 * their handles. |
| 199 */ | 203 */ |
| 200 template <class T> class Handle { | 204 template <class T> class Handle { |
| 201 public: | 205 public: |
| 202 /** | 206 /** |
| 203 * Creates an empty handle. | 207 * Creates an empty handle. |
| 204 */ | 208 */ |
| 205 V8_INLINE(Handle()) : val_(0) {} | 209 V8_INLINE(Handle()) : val_(0) {} |
| 206 | 210 |
| 211 #ifdef V8_USE_UNSAFE_HANDLES | |
| 207 /** | 212 /** |
| 208 * Creates a new handle for the specified value. | 213 * Creates a new handle for the specified value. |
| 209 */ | 214 */ |
| 210 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | 215 V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 216 #endif | |
| 211 | 217 |
| 212 /** | 218 /** |
| 213 * Creates a handle for the contents of the specified handle. This | 219 * Creates a handle for the contents of the specified handle. This |
| 214 * constructor allows you to pass handles as arguments by value and | 220 * constructor allows you to pass handles as arguments by value and |
| 215 * to assign between handles. However, if you try to assign between | 221 * to assign between handles. However, if you try to assign between |
| 216 * incompatible handles, for instance from a Handle<String> to a | 222 * incompatible handles, for instance from a Handle<String> to a |
| 217 * Handle<Number> it will cause a compile-time error. Assigning | 223 * Handle<Number> it will cause a compile-time error. Assigning |
| 218 * between compatible handles, for instance assigning a | 224 * between compatible handles, for instance assigning a |
| 219 * Handle<String> to a variable declared as Handle<Value>, is legal | 225 * Handle<String> to a variable declared as Handle<Value>, is legal |
| 220 * because String is a subclass of Value. | 226 * because String is a subclass of Value. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 242 V8_INLINE(T* operator->() const) { return val_; } | 248 V8_INLINE(T* operator->() const) { return val_; } |
| 243 | 249 |
| 244 V8_INLINE(T* operator*() const) { return val_; } | 250 V8_INLINE(T* operator*() const) { return val_; } |
| 245 | 251 |
| 246 /** | 252 /** |
| 247 * Checks whether two handles are the same. | 253 * Checks whether two handles are the same. |
| 248 * Returns true if both are empty, or if the objects | 254 * Returns true if both are empty, or if the objects |
| 249 * to which they refer are identical. | 255 * to which they refer are identical. |
| 250 * The handles' references are not checked. | 256 * The handles' references are not checked. |
| 251 */ | 257 */ |
| 252 template <class S> V8_INLINE(bool operator==(Handle<S> that) const) { | 258 template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 253 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 259 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 254 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 260 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 255 if (a == 0) return b == 0; | 261 if (a == 0) return b == 0; |
| 256 if (b == 0) return false; | 262 if (b == 0) return false; |
| 257 return *a == *b; | 263 return *a == *b; |
| 258 } | 264 } |
| 259 | 265 |
| 266 #ifndef V8_USE_UNSAFE_HANDLES | |
| 267 template <class S> V8_INLINE( | |
| 268 bool operator==(const Persistent<S>& that) const) { | |
| 269 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | |
| 270 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | |
| 271 if (a == 0) return b == 0; | |
| 272 if (b == 0) return false; | |
| 273 return *a == *b; | |
| 274 } | |
| 275 #endif | |
| 276 | |
| 260 /** | 277 /** |
| 261 * Checks whether two handles are different. | 278 * Checks whether two handles are different. |
| 262 * Returns true if only one of the handles is empty, or if | 279 * Returns true if only one of the handles is empty, or if |
| 263 * the objects to which they refer are different. | 280 * the objects to which they refer are different. |
| 264 * The handles' references are not checked. | 281 * The handles' references are not checked. |
| 265 */ | 282 */ |
| 266 template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { | 283 template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
| 267 return !operator==(that); | 284 return !operator==(that); |
| 268 } | 285 } |
| 269 | 286 |
| 270 template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) { | 287 template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) { |
| 271 #ifdef V8_ENABLE_CHECKS | 288 #ifdef V8_ENABLE_CHECKS |
| 272 // If we're going to perform the type check then we have to check | 289 // If we're going to perform the type check then we have to check |
| 273 // that the handle isn't empty before doing the checked cast. | 290 // that the handle isn't empty before doing the checked cast. |
| 274 if (that.IsEmpty()) return Handle<T>(); | 291 if (that.IsEmpty()) return Handle<T>(); |
| 275 #endif | 292 #endif |
| 276 return Handle<T>(T::Cast(*that)); | 293 return Handle<T>(T::Cast(*that)); |
| 277 } | 294 } |
| 278 | 295 |
| 279 template <class S> V8_INLINE(Handle<S> As()) { | 296 template <class S> V8_INLINE(Handle<S> As()) { |
| 280 return Handle<S>::Cast(*this); | 297 return Handle<S>::Cast(*this); |
| 281 } | 298 } |
| 282 | 299 |
| 300 #ifndef V8_USE_UNSAFE_HANDLES | |
| 301 V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { | |
| 302 return New(isolate, that.val_); | |
| 303 } | |
| 304 // TODO(dcarney): remove before cutover | |
| 305 V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { | |
| 306 return New(isolate, that.val_); | |
| 307 } | |
| 308 | |
| 309 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |
| 310 | |
| 283 private: | 311 private: |
| 312 #endif | |
| 313 /** | |
| 314 * Creates a new handle for the specified value. | |
| 315 */ | |
| 316 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | |
| 317 #endif | |
| 318 | |
| 319 private: | |
| 320 template<class F> | |
| 321 friend class Persistent; | |
| 322 template<class F> | |
| 323 friend class Local; | |
| 324 friend class Arguments; | |
| 325 friend class String; | |
| 326 friend class Object; | |
| 327 friend class AccessorInfo; | |
| 328 friend Handle<Primitive> Undefined(Isolate* isolate); | |
| 329 friend Handle<Primitive> Null(Isolate* isolate); | |
| 330 friend Handle<Boolean> True(Isolate* isolate); | |
| 331 friend Handle<Boolean> False(Isolate* isolate); | |
| 332 friend class Context; | |
| 333 friend class InternalHandleHelper; | |
| 334 friend class LocalContext; | |
| 335 | |
| 336 #ifndef V8_USE_UNSAFE_HANDLES | |
| 337 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); | |
| 338 #endif | |
| 339 | |
| 284 T* val_; | 340 T* val_; |
| 285 }; | 341 }; |
| 286 | 342 |
| 287 | 343 |
| 288 /** | 344 /** |
| 289 * A light-weight stack-allocated object handle. All operations | 345 * A light-weight stack-allocated object handle. All operations |
| 290 * that return objects from within v8 return them in local handles. They | 346 * that return objects from within v8 return them in local handles. They |
| 291 * are created within HandleScopes, and all local handles allocated within a | 347 * are created within HandleScopes, and all local handles allocated within a |
| 292 * handle scope are destroyed when the handle scope is destroyed. Hence it | 348 * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 293 * is not necessary to explicitly deallocate local handles. | 349 * is not necessary to explicitly deallocate local handles. |
| 294 */ | 350 */ |
| 351 // TODO(dcarney): deprecate entire class | |
| 295 template <class T> class Local : public Handle<T> { | 352 template <class T> class Local : public Handle<T> { |
| 296 public: | 353 public: |
| 297 V8_INLINE(Local()); | 354 V8_INLINE(Local()); |
| 298 template <class S> V8_INLINE(Local(Local<S> that)) | 355 template <class S> V8_INLINE(Local(Local<S> that)) |
| 299 : Handle<T>(reinterpret_cast<T*>(*that)) { | 356 : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 300 /** | 357 /** |
| 301 * This check fails when trying to convert between incompatible | 358 * This check fails when trying to convert between incompatible |
| 302 * handles. For example, converting from a Handle<String> to a | 359 * handles. For example, converting from a Handle<String> to a |
| 303 * Handle<Number>. | 360 * Handle<Number>. |
| 304 */ | 361 */ |
| 305 TYPE_CHECK(T, S); | 362 TYPE_CHECK(T, S); |
| 306 } | 363 } |
| 364 | |
| 365 | |
| 366 #ifdef V8_USE_UNSAFE_HANDLES | |
| 307 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | 367 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 368 #endif | |
| 369 | |
| 308 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { | 370 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { |
| 309 #ifdef V8_ENABLE_CHECKS | 371 #ifdef V8_ENABLE_CHECKS |
| 310 // If we're going to perform the type check then we have to check | 372 // If we're going to perform the type check then we have to check |
| 311 // that the handle isn't empty before doing the checked cast. | 373 // that the handle isn't empty before doing the checked cast. |
| 312 if (that.IsEmpty()) return Local<T>(); | 374 if (that.IsEmpty()) return Local<T>(); |
| 313 #endif | 375 #endif |
| 314 return Local<T>(T::Cast(*that)); | 376 return Local<T>(T::Cast(*that)); |
| 315 } | 377 } |
| 378 #ifndef V8_USE_UNSAFE_HANDLES | |
| 379 template <class S> V8_INLINE(Local(Handle<S> that)) | |
| 380 : Handle<T>(reinterpret_cast<T*>(*that)) { | |
| 381 TYPE_CHECK(T, S); | |
| 382 } | |
| 383 #endif | |
| 316 | 384 |
| 317 template <class S> V8_INLINE(Local<S> As()) { | 385 template <class S> V8_INLINE(Local<S> As()) { |
| 318 return Local<S>::Cast(*this); | 386 return Local<S>::Cast(*this); |
| 319 } | 387 } |
| 320 | 388 |
| 321 /** | 389 /** |
| 322 * Create a local handle for the content of another handle. | 390 * Create a local handle for the content of another handle. |
| 323 * The referee is kept alive by the local handle even when | 391 * The referee is kept alive by the local handle even when |
| 324 * the original handle is destroyed/disposed. | 392 * the original handle is destroyed/disposed. |
| 325 */ | 393 */ |
| 326 V8_INLINE(static Local<T> New(Handle<T> that)); | 394 V8_INLINE(static Local<T> New(Handle<T> that)); |
| 327 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); | 395 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
| 396 #ifndef V8_USE_UNSAFE_HANDLES | |
| 397 // TODO(dcarney): remove before cutover | |
| 398 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); | |
| 399 | |
| 400 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |
| 401 | |
| 402 private: | |
| 403 #endif | |
| 404 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | |
| 405 #endif | |
| 406 | |
| 407 private: | |
| 408 template<class F> | |
| 409 friend class Persistent; | |
| 410 template<class F> | |
| 411 friend class Handle; | |
| 412 friend class Arguments; | |
| 413 friend class String; | |
| 414 friend class Object; | |
| 415 friend class AccessorInfo; | |
| 416 friend class Context; | |
| 417 friend class InternalHandleHelper; | |
| 418 friend class LocalContext; | |
| 419 | |
| 420 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); | |
| 328 }; | 421 }; |
| 329 | 422 |
| 330 | |
| 331 /** | 423 /** |
| 332 * An object reference that is independent of any handle scope. Where | 424 * An object reference that is independent of any handle scope. Where |
| 333 * a Local handle only lives as long as the HandleScope in which it was | 425 * a Local handle only lives as long as the HandleScope in which it was |
| 334 * allocated, a Persistent handle remains valid until it is explicitly | 426 * allocated, a Persistent handle remains valid until it is explicitly |
| 335 * disposed. | 427 * disposed. |
| 336 * | 428 * |
| 337 * A persistent handle contains a reference to a storage cell within | 429 * A persistent handle contains a reference to a storage cell within |
| 338 * the v8 engine which holds an object value and which is updated by | 430 * the v8 engine which holds an object value and which is updated by |
| 339 * the garbage collector whenever the object is moved. A new storage | 431 * the garbage collector whenever the object is moved. A new storage |
| 340 * cell can be created using Persistent::New and existing handles can | 432 * cell can be created using Persistent::New and existing handles can |
| 341 * be disposed using Persistent::Dispose. Since persistent handles | 433 * be disposed using Persistent::Dispose. Since persistent handles |
| 342 * are passed by value you may have many persistent handle objects | 434 * are passed by value you may have many persistent handle objects |
| 343 * that point to the same storage cell. For instance, if you pass a | 435 * that point to the same storage cell. For instance, if you pass a |
| 344 * persistent handle as an argument to a function you will not get two | 436 * persistent handle as an argument to a function you will not get two |
| 345 * different storage cells but rather two references to the same | 437 * different storage cells but rather two references to the same |
| 346 * storage cell. | 438 * storage cell. |
| 347 */ | 439 */ |
| 348 template <class T> class Persistent : public Handle<T> { | 440 template <class T> class Persistent // NOLINT |
| 441 #ifdef V8_USE_UNSAFE_HANDLES | |
| 442 : public Handle<T> { | |
| 443 #else | |
| 444 { // NOLINT | |
| 445 #endif | |
| 349 public: | 446 public: |
| 447 #ifndef V8_USE_UNSAFE_HANDLES | |
| 448 V8_INLINE(Persistent()) : val_(0) { } | |
| 449 V8_INLINE(~Persistent()) { | |
| 450 // TODO(dcarney): add this back before cutover. | |
| 451 // Dispose(); | |
| 452 } | |
| 453 V8_INLINE(bool IsEmpty() const) { return val_ == 0; } | |
| 454 // TODO(dcarney): remove somehow before cutover | |
| 455 // The handle should either be 0, or a pointer to a live cell. | |
| 456 V8_INLINE(void Clear()) { val_ = 0; } | |
| 457 | |
| 458 /** | |
| 459 * A constructor that creates a new global cell pointing to that. In contrast | |
| 460 * to the copy constructor, this creates a new persistent handle which needs | |
| 461 * to be separately disposed. | |
| 462 */ | |
| 463 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) | |
| 464 : val_(*New(isolate, that)) { } | |
| 465 | |
| 466 #else | |
| 350 /** | 467 /** |
| 351 * Creates an empty persistent handle that doesn't point to any | 468 * Creates an empty persistent handle that doesn't point to any |
| 352 * storage cell. | 469 * storage cell. |
| 353 */ | 470 */ |
| 354 V8_INLINE(Persistent()); | 471 V8_INLINE(Persistent()) : Handle<T>() { } |
| 355 | 472 |
| 356 /** | 473 /** |
| 357 * Creates a persistent handle for the same storage cell as the | 474 * Creates a persistent handle for the same storage cell as the |
| 358 * specified handle. This constructor allows you to pass persistent | 475 * specified handle. This constructor allows you to pass persistent |
| 359 * handles as arguments by value and to assign between persistent | 476 * handles as arguments by value and to assign between persistent |
| 360 * handles. However, attempting to assign between incompatible | 477 * handles. However, attempting to assign between incompatible |
| 361 * persistent handles, for instance from a Persistent<String> to a | 478 * persistent handles, for instance from a Persistent<String> to a |
| 362 * Persistent<Number> will cause a compile-time error. Assigning | 479 * Persistent<Number> will cause a compile-time error. Assigning |
| 363 * between compatible persistent handles, for instance assigning a | 480 * between compatible persistent handles, for instance assigning a |
| 364 * Persistent<String> to a variable declared as Persistent<Value>, | 481 * Persistent<String> to a variable declared as Persistent<Value>, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 384 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) | 501 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 385 : Handle<T>(New(isolate, that)) { } | 502 : Handle<T>(New(isolate, that)) { } |
| 386 | 503 |
| 387 /** | 504 /** |
| 388 * "Casts" a plain handle which is known to be a persistent handle | 505 * "Casts" a plain handle which is known to be a persistent handle |
| 389 * to a persistent handle. | 506 * to a persistent handle. |
| 390 */ | 507 */ |
| 391 template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) | 508 template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
| 392 : Handle<T>(*that) { } | 509 : Handle<T>(*that) { } |
| 393 | 510 |
| 511 #endif | |
| 512 | |
| 394 template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { | 513 template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { |
| 395 #ifdef V8_ENABLE_CHECKS | 514 #ifdef V8_ENABLE_CHECKS |
| 396 // If we're going to perform the type check then we have to check | 515 // If we're going to perform the type check then we have to check |
| 397 // that the handle isn't empty before doing the checked cast. | 516 // that the handle isn't empty before doing the checked cast. |
| 398 if (that.IsEmpty()) return Persistent<T>(); | 517 if (that.IsEmpty()) return Persistent<T>(); |
| 399 #endif | 518 #endif |
| 400 return Persistent<T>(T::Cast(*that)); | 519 return Persistent<T>(T::Cast(*that)); |
| 401 } | 520 } |
| 402 | 521 |
| 403 template <class S> V8_INLINE(Persistent<S> As()) { | 522 template <class S> V8_INLINE(Persistent<S> As()) { |
| 404 return Persistent<S>::Cast(*this); | 523 return Persistent<S>::Cast(*this); |
| 405 } | 524 } |
| 406 | 525 |
| 407 /** Deprecated. Use Isolate version instead. */ | |
| 408 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); | 526 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 409 | 527 |
| 410 /** | 528 /** |
| 411 * Creates a new persistent handle for an existing local or persistent handle. | 529 * Creates a new persistent handle for an existing local or persistent handle. |
| 412 */ | 530 */ |
| 531 // TODO(dcarney): remove before cutover | |
| 413 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); | 532 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
| 533 #ifndef V8_USE_UNSAFE_HANDLES | |
| 534 // TODO(dcarney): remove before cutover | |
| 535 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); | |
| 536 #endif | |
| 414 | 537 |
| 415 /** Deprecated. Use Isolate version instead. */ | 538 #ifndef V8_USE_UNSAFE_HANDLES |
| 416 V8_DEPRECATED(void Dispose()); | 539 template <class S> V8_INLINE( |
| 540 bool operator==(const Persistent<S>& that) const) { | |
| 541 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | |
| 542 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | |
| 543 if (a == 0) return b == 0; | |
| 544 if (b == 0) return false; | |
| 545 return *a == *b; | |
| 546 } | |
| 547 | |
| 548 template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { | |
| 549 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | |
| 550 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | |
| 551 if (a == 0) return b == 0; | |
| 552 if (b == 0) return false; | |
| 553 return *a == *b; | |
| 554 } | |
| 555 #endif | |
| 556 | |
| 557 V8_INLINE(void Dispose()); | |
|
Sven Panne
2013/04/30 07:31:22
Why is V8_DEPRECATED changed to V8_INLINE here and
dcarney
2013/04/30 07:43:21
we need to revert that behaviour and change handle
| |
| 417 | 558 |
| 418 /** | 559 /** |
| 419 * Releases the storage cell referenced by this persistent handle. | 560 * Releases the storage cell referenced by this persistent handle. |
| 420 * Does not remove the reference to the cell from any handles. | 561 * Does not remove the reference to the cell from any handles. |
| 421 * This handle's reference, and any other references to the storage | 562 * This handle's reference, and any other references to the storage |
| 422 * cell remain and IsEmpty will still return false. | 563 * cell remain and IsEmpty will still return false. |
| 423 */ | 564 */ |
| 565 // TODO(dcarney): remove before cutover | |
| 424 V8_INLINE(void Dispose(Isolate* isolate)); | 566 V8_INLINE(void Dispose(Isolate* isolate)); |
| 425 | 567 |
| 426 /** Deprecated. Use Isolate version instead. */ | 568 V8_INLINE(void MakeWeak(void* parameters, |
| 427 V8_DEPRECATED(void MakeWeak(void* parameters, | |
| 428 WeakReferenceCallback callback)); | 569 WeakReferenceCallback callback)); |
| 429 | 570 |
| 430 /** | 571 /** |
| 431 * Make the reference to this object weak. When only weak handles | 572 * Make the reference to this object weak. When only weak handles |
| 432 * refer to the object, the garbage collector will perform a | 573 * refer to the object, the garbage collector will perform a |
| 433 * callback to the given V8::NearDeathCallback function, passing | 574 * callback to the given V8::NearDeathCallback function, passing |
| 434 * it the object reference and the given parameters. | 575 * it the object reference and the given parameters. |
| 435 */ | 576 */ |
| 577 // TODO(dcarney): remove before cutover | |
| 436 V8_INLINE(void MakeWeak(Isolate* isolate, | 578 V8_INLINE(void MakeWeak(Isolate* isolate, |
| 437 void* parameters, | 579 void* parameters, |
| 438 NearDeathCallback callback)); | 580 NearDeathCallback callback)); |
| 439 | 581 |
| 440 /** Deprecated. Use Isolate version instead. */ | 582 V8_INLINE(void ClearWeak()); |
| 441 V8_DEPRECATED(void ClearWeak()); | |
| 442 | 583 |
| 443 /** Clears the weak reference to this object. */ | 584 // TODO(dcarney): remove before cutover |
| 444 V8_INLINE(void ClearWeak(Isolate* isolate)); | 585 V8_INLINE(void ClearWeak(Isolate* isolate)); |
| 445 | 586 |
| 446 /** Deprecated. Use Isolate version instead. */ | 587 V8_INLINE(void MarkIndependent()); |
| 447 V8_DEPRECATED(void MarkIndependent()); | |
| 448 | 588 |
| 449 /** | 589 /** |
| 450 * Marks the reference to this object independent. Garbage collector is free | 590 * Marks the reference to this object independent. Garbage collector is free |
| 451 * to ignore any object groups containing this object. Weak callback for an | 591 * to ignore any object groups containing this object. Weak callback for an |
| 452 * independent handle should not assume that it will be preceded by a global | 592 * independent handle should not assume that it will be preceded by a global |
| 453 * GC prologue callback or followed by a global GC epilogue callback. | 593 * GC prologue callback or followed by a global GC epilogue callback. |
| 454 */ | 594 */ |
| 595 // TODO(dcarney): remove before cutover | |
| 455 V8_INLINE(void MarkIndependent(Isolate* isolate)); | 596 V8_INLINE(void MarkIndependent(Isolate* isolate)); |
| 456 | 597 |
| 457 /** Deprecated. Use Isolate version instead. */ | 598 V8_INLINE(void MarkPartiallyDependent()); |
| 458 V8_DEPRECATED(void MarkPartiallyDependent()); | |
| 459 | 599 |
| 460 /** | 600 /** |
| 461 * Marks the reference to this object partially dependent. Partially dependent | 601 * Marks the reference to this object partially dependent. Partially dependent |
| 462 * handles only depend on other partially dependent handles and these | 602 * handles only depend on other partially dependent handles and these |
| 463 * dependencies are provided through object groups. It provides a way to build | 603 * dependencies are provided through object groups. It provides a way to build |
| 464 * smaller object groups for young objects that represent only a subset of all | 604 * smaller object groups for young objects that represent only a subset of all |
| 465 * external dependencies. This mark is automatically cleared after each | 605 * external dependencies. This mark is automatically cleared after each |
| 466 * garbage collection. | 606 * garbage collection. |
| 467 */ | 607 */ |
| 608 // TODO(dcarney): remove before cutover | |
| 468 V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); | 609 V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
| 469 | 610 |
| 470 /** Deprecated. Use Isolate version instead. */ | 611 V8_INLINE(bool IsIndependent() const); |
| 471 V8_DEPRECATED(bool IsIndependent() const); | |
| 472 | 612 |
| 473 /** Returns true if this handle was previously marked as independent. */ | 613 // TODO(dcarney): remove before cutover |
| 474 V8_INLINE(bool IsIndependent(Isolate* isolate) const); | 614 V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
| 475 | 615 |
| 476 /** Deprecated. Use Isolate version instead. */ | 616 V8_INLINE(bool IsNearDeath() const); |
| 477 V8_DEPRECATED(bool IsNearDeath() const); | |
| 478 | 617 |
| 479 /** Checks if the handle holds the only reference to an object. */ | 618 /** Checks if the handle holds the only reference to an object. */ |
| 619 // TODO(dcarney): remove before cutover | |
| 480 V8_INLINE(bool IsNearDeath(Isolate* isolate) const); | 620 V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
| 481 | 621 |
| 482 /** Deprecated. Use Isolate version instead. */ | 622 V8_INLINE(bool IsWeak() const); |
| 483 V8_DEPRECATED(bool IsWeak() const); | |
| 484 | 623 |
| 485 /** Returns true if the handle's reference is weak. */ | 624 /** Returns true if the handle's reference is weak. */ |
| 625 // TODO(dcarney): remove before cutover | |
| 486 V8_INLINE(bool IsWeak(Isolate* isolate) const); | 626 V8_INLINE(bool IsWeak(Isolate* isolate) const); |
| 487 | 627 |
| 488 /** Deprecated. Use Isolate version instead. */ | 628 V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
| 489 V8_DEPRECATED(void SetWrapperClassId(uint16_t class_id)); | |
| 490 | 629 |
| 491 /** | 630 /** |
| 492 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface | 631 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 493 * description in v8-profiler.h for details. | 632 * description in v8-profiler.h for details. |
| 494 */ | 633 */ |
| 634 // TODO(dcarney): remove before cutover | |
| 495 V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); | 635 V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
| 496 | 636 |
| 497 /** Deprecated. Use Isolate version instead. */ | 637 V8_INLINE(uint16_t WrapperClassId() const); |
| 498 V8_DEPRECATED(uint16_t WrapperClassId() const); | |
| 499 | 638 |
| 500 /** | 639 /** |
| 501 * Returns the class ID previously assigned to this handle or 0 if no class ID | 640 * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 502 * was previously assigned. | 641 * was previously assigned. |
| 503 */ | 642 */ |
| 643 // TODO(dcarney): remove before cutover | |
| 504 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); | 644 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
| 505 | 645 |
| 646 #ifndef V8_USE_UNSAFE_HANDLES | |
| 647 | |
| 648 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT | |
| 649 | |
| 506 private: | 650 private: |
| 651 #endif | |
| 652 // TODO(dcarney): make unlinkable before cutover | |
| 653 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} | |
| 654 // TODO(dcarney): make unlinkable before cutover | |
| 655 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT | |
| 656 this->val_ = that.val_; | |
| 657 return *this; | |
| 658 } | |
| 659 | |
| 660 public: | |
| 661 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |
| 662 | |
| 663 private: | |
| 664 #endif | |
| 665 // TODO(dcarney): remove before cutover | |
| 666 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } | |
| 667 // TODO(dcarney): remove before cutover | |
| 668 template <class S> V8_INLINE(Persistent(Persistent<S> that)) | |
| 669 : val_(*that) { | |
| 670 TYPE_CHECK(T, S); | |
| 671 } | |
| 672 // TODO(dcarney): remove before cutover | |
| 673 V8_INLINE(T* operator*() const) { return val_; } | |
| 674 public: | |
| 675 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW | |
| 676 | |
| 677 private: | |
| 678 #endif | |
| 679 // TODO(dcarney): remove before cutover | |
| 680 V8_INLINE(T* operator->() const) { return val_; } | |
| 681 public: | |
| 682 #endif | |
| 683 | |
| 684 private: | |
| 685 template<class F> | |
| 686 friend class Handle; | |
| 687 template<class F> | |
| 688 friend class Local; | |
| 507 friend class ImplementationUtilities; | 689 friend class ImplementationUtilities; |
| 508 friend class ObjectTemplate; | 690 friend class ObjectTemplate; |
| 691 friend class Context; | |
| 692 friend class InternalHandleHelper; | |
| 693 friend class LocalContext; | |
| 694 | |
| 695 V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); | |
| 696 | |
| 697 #ifndef V8_USE_UNSAFE_HANDLES | |
| 698 T* val_; | |
| 699 #endif | |
| 509 }; | 700 }; |
| 510 | 701 |
| 511 | 702 |
| 512 /** | 703 /** |
| 513 * A stack-allocated class that governs a number of local handles. | 704 * A stack-allocated class that governs a number of local handles. |
| 514 * After a handle scope has been created, all local handles will be | 705 * After a handle scope has been created, all local handles will be |
| 515 * allocated within that handle scope until either the handle scope is | 706 * allocated within that handle scope until either the handle scope is |
| 516 * deleted or another handle scope is created. If there is already a | 707 * deleted or another handle scope is created. If there is already a |
| 517 * handle scope and a new one is created, all allocations will take | 708 * handle scope and a new one is created, all allocations will take |
| 518 * place in the new handle scope until it is deleted. After that, | 709 * place in the new handle scope until it is deleted. After that, |
| (...skipping 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4143 | 4334 |
| 4144 /** | 4335 /** |
| 4145 * Stack-allocated class which sets the execution context for all | 4336 * Stack-allocated class which sets the execution context for all |
| 4146 * operations executed within a local scope. | 4337 * operations executed within a local scope. |
| 4147 */ | 4338 */ |
| 4148 class Scope { | 4339 class Scope { |
| 4149 public: | 4340 public: |
| 4150 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { | 4341 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
| 4151 context_->Enter(); | 4342 context_->Enter(); |
| 4152 } | 4343 } |
| 4344 V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT | |
| 4345 #ifndef V8_USE_UNSAFE_HANDLES | |
| 4346 : context_(Handle<Context>::New(isolate, context)) { | |
| 4347 #else | |
| 4348 : context_(Local<Context>::New(isolate, context)) { | |
| 4349 #endif | |
| 4350 context_->Enter(); | |
| 4351 } | |
| 4153 V8_INLINE(~Scope()) { context_->Exit(); } | 4352 V8_INLINE(~Scope()) { context_->Exit(); } |
| 4353 | |
| 4154 private: | 4354 private: |
| 4155 Handle<Context> context_; | 4355 Handle<Context> context_; |
| 4156 }; | 4356 }; |
| 4157 | 4357 |
| 4158 private: | 4358 private: |
| 4159 friend class Value; | 4359 friend class Value; |
| 4160 friend class Script; | 4360 friend class Script; |
| 4161 friend class Object; | 4361 friend class Object; |
| 4162 friend class Function; | 4362 friend class Function; |
| 4163 | 4363 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4582 if (internal::Internals::CanCastToHeapObject(that_ptr)) { | 4782 if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 4583 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 4783 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 4584 reinterpret_cast<internal::HeapObject*>(*p)))); | 4784 reinterpret_cast<internal::HeapObject*>(*p)))); |
| 4585 } | 4785 } |
| 4586 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | 4786 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 4587 } | 4787 } |
| 4588 | 4788 |
| 4589 | 4789 |
| 4590 template <class T> | 4790 template <class T> |
| 4591 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | 4791 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
| 4592 if (that.IsEmpty()) return Local<T>(); | 4792 return New(isolate, that.val_); |
| 4593 T* that_ptr = *that; | 4793 } |
| 4794 | |
| 4795 #ifndef V8_USE_UNSAFE_HANDLES | |
| 4796 template <class T> | |
| 4797 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { | |
| 4798 return New(isolate, that.val_); | |
| 4799 } | |
| 4800 | |
| 4801 template <class T> | |
| 4802 Handle<T> Handle<T>::New(Isolate* isolate, T* that) { | |
| 4803 if (that == NULL) return Handle<T>(); | |
| 4804 T* that_ptr = that; | |
| 4805 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | |
| 4806 return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | |
| 4807 reinterpret_cast<internal::Isolate*>(isolate), *p))); | |
| 4808 } | |
| 4809 #endif | |
| 4810 | |
| 4811 | |
| 4812 template <class T> | |
| 4813 Local<T> Local<T>::New(Isolate* isolate, T* that) { | |
| 4814 if (that == NULL) return Local<T>(); | |
| 4815 T* that_ptr = that; | |
| 4594 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 4816 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 4595 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 4817 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 4596 reinterpret_cast<internal::Isolate*>(isolate), *p))); | 4818 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 4597 } | 4819 } |
| 4598 | 4820 |
| 4599 | 4821 |
| 4600 template <class T> | 4822 template <class T> |
| 4601 Persistent<T> Persistent<T>::New(Handle<T> that) { | 4823 Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 4602 return New(Isolate::GetCurrent(), that); | 4824 return New(Isolate::GetCurrent(), that.val_); |
| 4603 } | 4825 } |
| 4604 | 4826 |
| 4605 | 4827 |
| 4606 template <class T> | 4828 template <class T> |
| 4607 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { | 4829 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
| 4608 if (that.IsEmpty()) return Persistent<T>(); | 4830 return New(Isolate::GetCurrent(), that.val_); |
| 4609 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 4831 } |
| 4832 | |
| 4833 #ifndef V8_USE_UNSAFE_HANDLES | |
| 4834 template <class T> | |
| 4835 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { | |
| 4836 return New(Isolate::GetCurrent(), that.val_); | |
| 4837 } | |
| 4838 #endif | |
| 4839 | |
| 4840 template <class T> | |
| 4841 Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { | |
| 4842 if (that == NULL) return Persistent<T>(); | |
| 4843 internal::Object** p = reinterpret_cast<internal::Object**>(that); | |
| 4610 return Persistent<T>(reinterpret_cast<T*>( | 4844 return Persistent<T>(reinterpret_cast<T*>( |
| 4611 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | 4845 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 4612 p))); | 4846 p))); |
| 4613 } | 4847 } |
| 4614 | 4848 |
| 4615 | 4849 |
| 4616 template <class T> | 4850 template <class T> |
| 4617 bool Persistent<T>::IsIndependent() const { | 4851 bool Persistent<T>::IsIndependent() const { |
| 4618 return IsIndependent(Isolate::GetCurrent()); | 4852 return IsIndependent(Isolate::GetCurrent()); |
| 4619 } | 4853 } |
| 4620 | 4854 |
| 4621 | 4855 |
| 4622 template <class T> | 4856 template <class T> |
| 4623 bool Persistent<T>::IsIndependent(Isolate* isolate) const { | 4857 bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
| 4624 typedef internal::Internals I; | 4858 typedef internal::Internals I; |
| 4625 if (this->IsEmpty()) return false; | 4859 if (this->IsEmpty()) return false; |
| 4626 if (!I::IsInitialized(isolate)) return false; | 4860 if (!I::IsInitialized(isolate)) return false; |
| 4627 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(**this), | 4861 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 4628 I::kNodeIsIndependentShift); | 4862 I::kNodeIsIndependentShift); |
| 4629 } | 4863 } |
| 4630 | 4864 |
| 4631 | 4865 |
| 4632 template <class T> | 4866 template <class T> |
| 4633 bool Persistent<T>::IsNearDeath() const { | 4867 bool Persistent<T>::IsNearDeath() const { |
| 4634 return IsNearDeath(Isolate::GetCurrent()); | 4868 return IsNearDeath(Isolate::GetCurrent()); |
| 4635 } | 4869 } |
| 4636 | 4870 |
| 4637 | 4871 |
| 4638 template <class T> | 4872 template <class T> |
| 4639 bool Persistent<T>::IsNearDeath(Isolate* isolate) const { | 4873 bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
| 4640 typedef internal::Internals I; | 4874 typedef internal::Internals I; |
| 4641 if (this->IsEmpty()) return false; | 4875 if (this->IsEmpty()) return false; |
| 4642 if (!I::IsInitialized(isolate)) return false; | 4876 if (!I::IsInitialized(isolate)) return false; |
| 4643 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) == | 4877 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
| 4644 I::kNodeStateIsNearDeathValue; | 4878 I::kNodeStateIsNearDeathValue; |
| 4645 } | 4879 } |
| 4646 | 4880 |
| 4647 | 4881 |
| 4648 template <class T> | 4882 template <class T> |
| 4649 bool Persistent<T>::IsWeak() const { | 4883 bool Persistent<T>::IsWeak() const { |
| 4650 return IsWeak(Isolate::GetCurrent()); | 4884 return IsWeak(Isolate::GetCurrent()); |
| 4651 } | 4885 } |
| 4652 | 4886 |
| 4653 | 4887 |
| 4654 template <class T> | 4888 template <class T> |
| 4655 bool Persistent<T>::IsWeak(Isolate* isolate) const { | 4889 bool Persistent<T>::IsWeak(Isolate* isolate) const { |
| 4656 typedef internal::Internals I; | 4890 typedef internal::Internals I; |
| 4657 if (this->IsEmpty()) return false; | 4891 if (this->IsEmpty()) return false; |
| 4658 if (!I::IsInitialized(isolate)) return false; | 4892 if (!I::IsInitialized(isolate)) return false; |
| 4659 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) == | 4893 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
| 4660 I::kNodeStateIsWeakValue; | 4894 I::kNodeStateIsWeakValue; |
| 4661 } | 4895 } |
| 4662 | 4896 |
| 4663 | 4897 |
| 4664 template <class T> | 4898 template <class T> |
| 4665 void Persistent<T>::Dispose() { | 4899 void Persistent<T>::Dispose() { |
| 4666 Dispose(Isolate::GetCurrent()); | 4900 Dispose(Isolate::GetCurrent()); |
| 4667 } | 4901 } |
| 4668 | 4902 |
| 4669 | 4903 |
| 4670 template <class T> | 4904 template <class T> |
| 4671 void Persistent<T>::Dispose(Isolate* isolate) { | 4905 void Persistent<T>::Dispose(Isolate* isolate) { |
| 4672 if (this->IsEmpty()) return; | 4906 if (this->IsEmpty()) return; |
| 4673 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), | 4907 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), |
| 4674 reinterpret_cast<internal::Object**>(**this)); | 4908 reinterpret_cast<internal::Object**>(this->val_)); |
| 4909 #ifndef V8_USE_UNSAFE_HANDLES | |
| 4910 val_ = 0; | |
| 4911 #endif | |
| 4675 } | 4912 } |
| 4676 | 4913 |
| 4677 | 4914 |
| 4678 template <class T> | 4915 template <class T> |
| 4679 Persistent<T>::Persistent() : Handle<T>() { } | |
| 4680 | |
| 4681 template <class T> | |
| 4682 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { | 4916 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { |
| 4683 Isolate* isolate = Isolate::GetCurrent(); | 4917 Isolate* isolate = Isolate::GetCurrent(); |
| 4684 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | 4918 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
| 4685 reinterpret_cast<internal::Object**>(**this), | 4919 reinterpret_cast<internal::Object**>(this->val_), |
| 4686 parameters, | 4920 parameters, |
| 4687 callback, | 4921 callback, |
| 4688 NULL); | 4922 NULL); |
| 4689 } | 4923 } |
| 4690 | 4924 |
| 4691 template <class T> | 4925 template <class T> |
| 4692 void Persistent<T>::MakeWeak(Isolate* isolate, | 4926 void Persistent<T>::MakeWeak(Isolate* isolate, |
| 4693 void* parameters, | 4927 void* parameters, |
| 4694 NearDeathCallback callback) { | 4928 NearDeathCallback callback) { |
| 4695 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | 4929 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
| 4696 reinterpret_cast<internal::Object**>(**this), | 4930 reinterpret_cast<internal::Object**>(this->val_), |
| 4697 parameters, | 4931 parameters, |
| 4698 NULL, | 4932 NULL, |
| 4699 callback); | 4933 callback); |
| 4700 } | 4934 } |
| 4701 | 4935 |
| 4702 template <class T> | 4936 template <class T> |
| 4703 void Persistent<T>::ClearWeak() { | 4937 void Persistent<T>::ClearWeak() { |
| 4704 ClearWeak(Isolate::GetCurrent()); | 4938 ClearWeak(Isolate::GetCurrent()); |
| 4705 } | 4939 } |
| 4706 | 4940 |
| 4707 template <class T> | 4941 template <class T> |
| 4708 void Persistent<T>::ClearWeak(Isolate* isolate) { | 4942 void Persistent<T>::ClearWeak(Isolate* isolate) { |
| 4709 V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), | 4943 V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
| 4710 reinterpret_cast<internal::Object**>(**this)); | 4944 reinterpret_cast<internal::Object**>(this->val_)); |
| 4711 } | 4945 } |
| 4712 | 4946 |
| 4713 template <class T> | 4947 template <class T> |
| 4714 void Persistent<T>::MarkIndependent() { | 4948 void Persistent<T>::MarkIndependent() { |
| 4715 MarkIndependent(Isolate::GetCurrent()); | 4949 MarkIndependent(Isolate::GetCurrent()); |
| 4716 } | 4950 } |
| 4717 | 4951 |
| 4718 template <class T> | 4952 template <class T> |
| 4719 void Persistent<T>::MarkIndependent(Isolate* isolate) { | 4953 void Persistent<T>::MarkIndependent(Isolate* isolate) { |
| 4720 typedef internal::Internals I; | 4954 typedef internal::Internals I; |
| 4721 if (this->IsEmpty()) return; | 4955 if (this->IsEmpty()) return; |
| 4722 if (!I::IsInitialized(isolate)) return; | 4956 if (!I::IsInitialized(isolate)) return; |
| 4723 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this), | 4957 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 4724 true, | 4958 true, |
| 4725 I::kNodeIsIndependentShift); | 4959 I::kNodeIsIndependentShift); |
| 4726 } | 4960 } |
| 4727 | 4961 |
| 4728 template <class T> | 4962 template <class T> |
| 4729 void Persistent<T>::MarkPartiallyDependent() { | 4963 void Persistent<T>::MarkPartiallyDependent() { |
| 4730 MarkPartiallyDependent(Isolate::GetCurrent()); | 4964 MarkPartiallyDependent(Isolate::GetCurrent()); |
| 4731 } | 4965 } |
| 4732 | 4966 |
| 4733 template <class T> | 4967 template <class T> |
| 4734 void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { | 4968 void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
| 4735 typedef internal::Internals I; | 4969 typedef internal::Internals I; |
| 4736 if (this->IsEmpty()) return; | 4970 if (this->IsEmpty()) return; |
| 4737 if (!I::IsInitialized(isolate)) return; | 4971 if (!I::IsInitialized(isolate)) return; |
| 4738 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this), | 4972 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 4739 true, | 4973 true, |
| 4740 I::kNodeIsPartiallyDependentShift); | 4974 I::kNodeIsPartiallyDependentShift); |
| 4741 } | 4975 } |
| 4742 | 4976 |
| 4743 template <class T> | 4977 template <class T> |
| 4744 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | 4978 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
| 4745 SetWrapperClassId(Isolate::GetCurrent(), class_id); | 4979 SetWrapperClassId(Isolate::GetCurrent(), class_id); |
| 4746 } | 4980 } |
| 4747 | 4981 |
| 4748 template <class T> | 4982 template <class T> |
| 4749 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { | 4983 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
| 4750 typedef internal::Internals I; | 4984 typedef internal::Internals I; |
| 4751 if (this->IsEmpty()) return; | 4985 if (this->IsEmpty()) return; |
| 4752 if (!I::IsInitialized(isolate)) return; | 4986 if (!I::IsInitialized(isolate)) return; |
| 4753 internal::Object** obj = reinterpret_cast<internal::Object**>(**this); | 4987 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
| 4754 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 4988 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 4755 *reinterpret_cast<uint16_t*>(addr) = class_id; | 4989 *reinterpret_cast<uint16_t*>(addr) = class_id; |
| 4756 } | 4990 } |
| 4757 | 4991 |
| 4758 template <class T> | 4992 template <class T> |
| 4759 uint16_t Persistent<T>::WrapperClassId() const { | 4993 uint16_t Persistent<T>::WrapperClassId() const { |
| 4760 return WrapperClassId(Isolate::GetCurrent()); | 4994 return WrapperClassId(Isolate::GetCurrent()); |
| 4761 } | 4995 } |
| 4762 | 4996 |
| 4763 template <class T> | 4997 template <class T> |
| 4764 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { | 4998 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
| 4765 typedef internal::Internals I; | 4999 typedef internal::Internals I; |
| 4766 if (this->IsEmpty()) return 0; | 5000 if (this->IsEmpty()) return 0; |
| 4767 if (!I::IsInitialized(isolate)) return 0; | 5001 if (!I::IsInitialized(isolate)) return 0; |
| 4768 internal::Object** obj = reinterpret_cast<internal::Object**>(**this); | 5002 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
| 4769 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5003 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 4770 return *reinterpret_cast<uint16_t*>(addr); | 5004 return *reinterpret_cast<uint16_t*>(addr); |
| 4771 } | 5005 } |
| 4772 | 5006 |
| 4773 Arguments::Arguments(internal::Object** implicit_args, | 5007 Arguments::Arguments(internal::Object** implicit_args, |
| 4774 internal::Object** values, int length, | 5008 internal::Object** values, int length, |
| 4775 bool is_construct_call) | 5009 bool is_construct_call) |
| 4776 : implicit_args_(implicit_args), | 5010 : implicit_args_(implicit_args), |
| 4777 values_(values), | 5011 values_(values), |
| 4778 length_(length), | 5012 length_(length), |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5229 | 5463 |
| 5230 | 5464 |
| 5231 } // namespace v8 | 5465 } // namespace v8 |
| 5232 | 5466 |
| 5233 | 5467 |
| 5234 #undef V8EXPORT | 5468 #undef V8EXPORT |
| 5235 #undef TYPE_CHECK | 5469 #undef TYPE_CHECK |
| 5236 | 5470 |
| 5237 | 5471 |
| 5238 #endif // V8_H_ | 5472 #endif // V8_H_ |
| OLD | NEW |