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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 class StackTrace; | 138 class StackTrace; |
| 139 class String; | 139 class String; |
| 140 class StringObject; | 140 class StringObject; |
| 141 class Symbol; | 141 class Symbol; |
| 142 class SymbolObject; | 142 class SymbolObject; |
| 143 class Uint32; | 143 class Uint32; |
| 144 class Utils; | 144 class Utils; |
| 145 class Value; | 145 class Value; |
| 146 template <class T> class Handle; | 146 template <class T> class Handle; |
| 147 template <class T> class Local; | 147 template <class T> class Local; |
| 148 template <class T> class Persistent; | 148 template<class T> class NonCopyablePersistentTraits; |
| 149 template<class T, | |
| 150 class M = NonCopyablePersistentTraits<T> > class Persistent; | |
| 151 template<class T, class P> class WeakCallbackObject; | |
| 149 class FunctionTemplate; | 152 class FunctionTemplate; |
| 150 class ObjectTemplate; | 153 class ObjectTemplate; |
| 151 class Data; | 154 class Data; |
| 152 class AccessorInfo; | 155 class AccessorInfo; |
| 153 template<typename T> class PropertyCallbackInfo; | 156 template<typename T> class PropertyCallbackInfo; |
| 154 class StackTrace; | 157 class StackTrace; |
| 155 class StackFrame; | 158 class StackFrame; |
| 156 class Isolate; | 159 class Isolate; |
| 157 class DeclaredAccessorDescriptor; | 160 class DeclaredAccessorDescriptor; |
| 158 class ObjectOperationDescriptor; | 161 class ObjectOperationDescriptor; |
| 159 class RawOperationDescriptor; | 162 class RawOperationDescriptor; |
| 160 class CallHandlerHelper; | 163 class CallHandlerHelper; |
| 161 | 164 |
| 162 namespace internal { | 165 namespace internal { |
| 163 class Arguments; | 166 class Arguments; |
| 164 class Heap; | 167 class Heap; |
| 165 class HeapObject; | 168 class HeapObject; |
| 166 class Isolate; | 169 class Isolate; |
| 167 class Object; | 170 class Object; |
| 168 template<typename T> class CustomArguments; | 171 template<typename T> class CustomArguments; |
| 169 class PropertyCallbackArguments; | 172 class PropertyCallbackArguments; |
| 170 class FunctionCallbackArguments; | 173 class FunctionCallbackArguments; |
| 174 class GlobalHandles; | |
| 171 } | 175 } |
| 172 | 176 |
| 173 | 177 |
| 174 /** | 178 /** |
| 175 * General purpose unique identifier. | 179 * General purpose unique identifier. |
| 176 */ | 180 */ |
| 177 class UniqueId { | 181 class UniqueId { |
| 178 public: | 182 public: |
| 179 explicit UniqueId(intptr_t data) | 183 explicit UniqueId(intptr_t data) |
| 180 : data_(data) {} | 184 : data_(data) {} |
| 181 | 185 |
| 182 bool operator==(const UniqueId& other) const { | 186 bool operator==(const UniqueId& other) const { |
| 183 return data_ == other.data_; | 187 return data_ == other.data_; |
| 184 } | 188 } |
| 185 | 189 |
| 186 bool operator!=(const UniqueId& other) const { | 190 bool operator!=(const UniqueId& other) const { |
| 187 return data_ != other.data_; | 191 return data_ != other.data_; |
| 188 } | 192 } |
| 189 | 193 |
| 190 bool operator<(const UniqueId& other) const { | 194 bool operator<(const UniqueId& other) const { |
| 191 return data_ < other.data_; | 195 return data_ < other.data_; |
| 192 } | 196 } |
| 193 | 197 |
| 194 private: | 198 private: |
| 195 intptr_t data_; | 199 intptr_t data_; |
| 196 }; | 200 }; |
| 197 | 201 |
| 198 | |
| 199 // --- Weak Handles --- | |
| 200 | |
| 201 | |
| 202 /** | |
| 203 * A weak reference callback function. | |
| 204 * | |
| 205 * This callback should either explicitly invoke Dispose on |object| if | |
| 206 * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. | |
| 207 * | |
| 208 * \param object the weak global object to be reclaimed by the garbage collector | |
| 209 * \param parameter the value passed in when making the weak global object | |
| 210 */ | |
| 211 template<typename T, typename P> | |
| 212 class WeakReferenceCallbacks { | |
| 213 public: | |
| 214 typedef void (*Revivable)(Isolate* isolate, | |
| 215 Persistent<T>* object, | |
| 216 P* parameter); | |
| 217 }; | |
| 218 | |
| 219 // --- Handles --- | 202 // --- Handles --- |
| 220 | 203 |
| 221 #define TYPE_CHECK(T, S) \ | 204 #define TYPE_CHECK(T, S) \ |
| 222 while (false) { \ | 205 while (false) { \ |
| 223 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | 206 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
| 224 } | 207 } |
| 225 | 208 |
| 226 | 209 |
| 227 /** | 210 /** |
| 228 * An object reference managed by the v8 garbage collector. | 211 * An object reference managed by the v8 garbage collector. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 249 * behind the scenes and the same rules apply to these values as to | 232 * behind the scenes and the same rules apply to these values as to |
| 250 * their handles. | 233 * their handles. |
| 251 */ | 234 */ |
| 252 template <class T> class Handle { | 235 template <class T> class Handle { |
| 253 public: | 236 public: |
| 254 /** | 237 /** |
| 255 * Creates an empty handle. | 238 * Creates an empty handle. |
| 256 */ | 239 */ |
| 257 V8_INLINE(Handle()) : val_(0) {} | 240 V8_INLINE(Handle()) : val_(0) {} |
| 258 | 241 |
| 259 #ifdef V8_USE_UNSAFE_HANDLES | |
| 260 /** | |
| 261 * Creates a new handle for the specified value. | |
| 262 */ | |
| 263 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | |
| 264 #endif | |
| 265 | |
| 266 /** | 242 /** |
| 267 * Creates a handle for the contents of the specified handle. This | 243 * Creates a handle for the contents of the specified handle. This |
| 268 * constructor allows you to pass handles as arguments by value and | 244 * constructor allows you to pass handles as arguments by value and |
| 269 * to assign between handles. However, if you try to assign between | 245 * to assign between handles. However, if you try to assign between |
| 270 * incompatible handles, for instance from a Handle<String> to a | 246 * incompatible handles, for instance from a Handle<String> to a |
| 271 * Handle<Number> it will cause a compile-time error. Assigning | 247 * Handle<Number> it will cause a compile-time error. Assigning |
| 272 * between compatible handles, for instance assigning a | 248 * between compatible handles, for instance assigning a |
| 273 * Handle<String> to a variable declared as Handle<Value>, is legal | 249 * Handle<String> to a variable declared as Handle<Value>, is legal |
| 274 * because String is a subclass of Value. | 250 * because String is a subclass of Value. |
| 275 */ | 251 */ |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 304 * The handles' references are not checked. | 280 * The handles' references are not checked. |
| 305 */ | 281 */ |
| 306 template <class S> V8_INLINE(bool operator==(const Handle<S>& that) const) { | 282 template <class S> V8_INLINE(bool operator==(const Handle<S>& that) const) { |
| 307 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 283 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 308 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 284 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 309 if (a == 0) return b == 0; | 285 if (a == 0) return b == 0; |
| 310 if (b == 0) return false; | 286 if (b == 0) return false; |
| 311 return *a == *b; | 287 return *a == *b; |
| 312 } | 288 } |
| 313 | 289 |
| 314 #ifndef V8_USE_UNSAFE_HANDLES | |
|
marja
2013/08/23 13:02:40
Would it be feasible to just do one round of V8_US
dcarney
2013/08/23 13:06:10
I announced in the mailing list that I'd do this.
marja
2013/08/26 07:08:14
Fair enough. In that case, would it be feasible to
| |
| 315 template <class S> V8_INLINE( | 290 template <class S> V8_INLINE( |
| 316 bool operator==(const Persistent<S>& that) const) { | 291 bool operator==(const Persistent<S>& that) const) { |
| 317 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 292 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 318 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 293 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 319 if (a == 0) return b == 0; | 294 if (a == 0) return b == 0; |
| 320 if (b == 0) return false; | 295 if (b == 0) return false; |
| 321 return *a == *b; | 296 return *a == *b; |
| 322 } | 297 } |
| 323 #endif | |
| 324 | 298 |
| 325 /** | 299 /** |
| 326 * Checks whether two handles are different. | 300 * Checks whether two handles are different. |
| 327 * Returns true if only one of the handles is empty, or if | 301 * Returns true if only one of the handles is empty, or if |
| 328 * the objects to which they refer are different. | 302 * the objects to which they refer are different. |
| 329 * The handles' references are not checked. | 303 * The handles' references are not checked. |
| 330 */ | 304 */ |
| 331 template <class S> V8_INLINE(bool operator!=(const Handle<S>& that) const) { | 305 template <class S> V8_INLINE(bool operator!=(const Handle<S>& that) const) { |
| 332 return !operator==(that); | 306 return !operator==(that); |
| 333 } | 307 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 345 // that the handle isn't empty before doing the checked cast. | 319 // that the handle isn't empty before doing the checked cast. |
| 346 if (that.IsEmpty()) return Handle<T>(); | 320 if (that.IsEmpty()) return Handle<T>(); |
| 347 #endif | 321 #endif |
| 348 return Handle<T>(T::Cast(*that)); | 322 return Handle<T>(T::Cast(*that)); |
| 349 } | 323 } |
| 350 | 324 |
| 351 template <class S> V8_INLINE(Handle<S> As()) { | 325 template <class S> V8_INLINE(Handle<S> As()) { |
| 352 return Handle<S>::Cast(*this); | 326 return Handle<S>::Cast(*this); |
| 353 } | 327 } |
| 354 | 328 |
| 355 #ifndef V8_USE_UNSAFE_HANDLES | |
| 356 V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { | 329 V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 357 return New(isolate, that.val_); | 330 return New(isolate, that.val_); |
| 358 } | 331 } |
| 359 // TODO(dcarney): remove before cutover | |
| 360 V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { | 332 V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 361 return New(isolate, that.val_); | 333 return New(isolate, that.val_); |
| 362 } | 334 } |
| 363 | 335 |
| 364 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 336 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 365 | 337 |
| 366 private: | 338 private: |
| 367 #endif | 339 #endif |
| 368 /** | 340 /** |
| 369 * Creates a new handle for the specified value. | 341 * Creates a new handle for the specified value. |
| 370 */ | 342 */ |
| 371 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | 343 V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 372 #endif | |
| 373 | 344 |
| 374 private: | 345 private: |
| 375 friend class Utils; | 346 friend class Utils; |
| 376 template<class F> friend class Persistent; | 347 template<class F, class M> friend class Persistent; |
| 377 template<class F> friend class Local; | 348 template<class F> friend class Local; |
| 378 friend class Arguments; | 349 friend class Arguments; |
| 379 template<class F> friend class FunctionCallbackInfo; | 350 template<class F> friend class FunctionCallbackInfo; |
| 380 template<class F> friend class PropertyCallbackInfo; | 351 template<class F> friend class PropertyCallbackInfo; |
| 381 template<class F> friend class internal::CustomArguments; | 352 template<class F> friend class internal::CustomArguments; |
| 382 friend class AccessorInfo; | 353 friend class AccessorInfo; |
| 383 friend Handle<Primitive> Undefined(Isolate* isolate); | 354 friend Handle<Primitive> Undefined(Isolate* isolate); |
| 384 friend Handle<Primitive> Null(Isolate* isolate); | 355 friend Handle<Primitive> Null(Isolate* isolate); |
| 385 friend Handle<Boolean> True(Isolate* isolate); | 356 friend Handle<Boolean> True(Isolate* isolate); |
| 386 friend Handle<Boolean> False(Isolate* isolate); | 357 friend Handle<Boolean> False(Isolate* isolate); |
| 387 friend class Context; | 358 friend class Context; |
| 388 friend class HandleScope; | 359 friend class HandleScope; |
| 389 | 360 |
| 390 #ifndef V8_USE_UNSAFE_HANDLES | |
| 391 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); | 361 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 392 #endif | |
| 393 | 362 |
| 394 T* val_; | 363 T* val_; |
| 395 }; | 364 }; |
| 396 | 365 |
| 397 | 366 |
| 398 // A value which will never be returned by Local::Eternalize | 367 // A value which will never be returned by Local::Eternalize |
| 399 // Useful for static initialization | 368 // Useful for static initialization |
| 400 const int kUninitializedEternalIndex = -1; | 369 const int kUninitializedEternalIndex = -1; |
| 401 | 370 |
| 402 | 371 |
| 403 /** | 372 /** |
| 404 * A light-weight stack-allocated object handle. All operations | 373 * A light-weight stack-allocated object handle. All operations |
| 405 * that return objects from within v8 return them in local handles. They | 374 * that return objects from within v8 return them in local handles. They |
| 406 * are created within HandleScopes, and all local handles allocated within a | 375 * are created within HandleScopes, and all local handles allocated within a |
| 407 * handle scope are destroyed when the handle scope is destroyed. Hence it | 376 * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 408 * is not necessary to explicitly deallocate local handles. | 377 * is not necessary to explicitly deallocate local handles. |
| 409 */ | 378 */ |
| 410 // TODO(dcarney): deprecate entire class | |
| 411 template <class T> class Local : public Handle<T> { | 379 template <class T> class Local : public Handle<T> { |
| 412 public: | 380 public: |
| 413 V8_INLINE(Local()); | 381 V8_INLINE(Local()); |
| 414 template <class S> V8_INLINE(Local(Local<S> that)) | 382 template <class S> V8_INLINE(Local(Local<S> that)) |
| 415 : Handle<T>(reinterpret_cast<T*>(*that)) { | 383 : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 416 /** | 384 /** |
| 417 * This check fails when trying to convert between incompatible | 385 * This check fails when trying to convert between incompatible |
| 418 * handles. For example, converting from a Handle<String> to a | 386 * handles. For example, converting from a Handle<String> to a |
| 419 * Handle<Number>. | 387 * Handle<Number>. |
| 420 */ | 388 */ |
| 421 TYPE_CHECK(T, S); | 389 TYPE_CHECK(T, S); |
| 422 } | 390 } |
| 423 | 391 |
| 424 | 392 |
| 425 #ifdef V8_USE_UNSAFE_HANDLES | |
| 426 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | |
| 427 #endif | |
| 428 | |
| 429 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { | 393 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { |
| 430 #ifdef V8_ENABLE_CHECKS | 394 #ifdef V8_ENABLE_CHECKS |
| 431 // If we're going to perform the type check then we have to check | 395 // If we're going to perform the type check then we have to check |
| 432 // that the handle isn't empty before doing the checked cast. | 396 // that the handle isn't empty before doing the checked cast. |
| 433 if (that.IsEmpty()) return Local<T>(); | 397 if (that.IsEmpty()) return Local<T>(); |
| 434 #endif | 398 #endif |
| 435 return Local<T>(T::Cast(*that)); | 399 return Local<T>(T::Cast(*that)); |
| 436 } | 400 } |
| 437 #ifndef V8_USE_UNSAFE_HANDLES | |
| 438 template <class S> V8_INLINE(Local(Handle<S> that)) | 401 template <class S> V8_INLINE(Local(Handle<S> that)) |
| 439 : Handle<T>(reinterpret_cast<T*>(*that)) { | 402 : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 440 TYPE_CHECK(T, S); | 403 TYPE_CHECK(T, S); |
| 441 } | 404 } |
| 442 #endif | |
| 443 | 405 |
| 444 template <class S> V8_INLINE(Local<S> As()) { | 406 template <class S> V8_INLINE(Local<S> As()) { |
| 445 return Local<S>::Cast(*this); | 407 return Local<S>::Cast(*this); |
| 446 } | 408 } |
| 447 | 409 |
| 448 // Keep this Local alive for the lifetime of the Isolate. | 410 // Keep this Local alive for the lifetime of the Isolate. |
| 449 // It remains retrievable via the returned index, | 411 // It remains retrievable via the returned index, |
| 450 V8_INLINE(int Eternalize(Isolate* isolate)); | 412 V8_INLINE(int Eternalize(Isolate* isolate)); |
| 451 V8_INLINE(static Local<T> GetEternal(Isolate* isolate, int index)); | 413 V8_INLINE(static Local<T> GetEternal(Isolate* isolate, int index)); |
| 452 | 414 |
| 453 /** | 415 /** |
| 454 * Create a local handle for the content of another handle. | 416 * Create a local handle for the content of another handle. |
| 455 * The referee is kept alive by the local handle even when | 417 * The referee is kept alive by the local handle even when |
| 456 * the original handle is destroyed/disposed. | 418 * the original handle is destroyed/disposed. |
| 457 */ | 419 */ |
| 458 V8_INLINE(static Local<T> New(Handle<T> that)); | 420 V8_INLINE(static Local<T> New(Handle<T> that)); |
| 459 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); | 421 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
| 460 #ifndef V8_USE_UNSAFE_HANDLES | 422 template<class M> |
| 461 // TODO(dcarney): remove before cutover | 423 V8_INLINE(static Local<T> New(Isolate* isolate, |
| 462 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); | 424 const Persistent<T, M>& that)); |
| 463 | 425 |
| 464 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 426 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 465 | 427 |
| 466 private: | 428 private: |
| 467 #endif | 429 #endif |
| 468 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | 430 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 469 #endif | |
| 470 | 431 |
| 471 private: | 432 private: |
| 472 friend class Utils; | 433 friend class Utils; |
| 473 template<class F> friend class Persistent; | 434 template<class F, class M> friend class Persistent; |
| 474 template<class F> friend class Handle; | 435 template<class F> friend class Handle; |
| 475 friend class Arguments; | 436 friend class Arguments; |
| 476 template<class F> friend class FunctionCallbackInfo; | 437 template<class F> friend class FunctionCallbackInfo; |
| 477 template<class F> friend class PropertyCallbackInfo; | 438 template<class F> friend class PropertyCallbackInfo; |
| 478 friend class String; | 439 friend class String; |
| 479 friend class Object; | 440 friend class Object; |
| 480 friend class AccessorInfo; | 441 friend class AccessorInfo; |
| 481 friend class Context; | 442 friend class Context; |
| 482 template<class F> friend class internal::CustomArguments; | 443 template<class F> friend class internal::CustomArguments; |
| 483 friend class HandleScope; | 444 friend class HandleScope; |
| 484 | 445 |
| 485 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); | 446 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 486 }; | 447 }; |
| 487 | 448 |
| 488 /** | 449 |
| 489 * An object reference that is independent of any handle scope. Where | 450 // TODO(dcarney): comments |
| 490 * a Local handle only lives as long as the HandleScope in which it was | 451 template<class T, class P> |
| 491 * allocated, a Persistent handle remains valid until it is explicitly | 452 class WeakCallbackData { |
| 492 * disposed. | |
| 493 * | |
| 494 * A persistent handle contains a reference to a storage cell within | |
| 495 * the v8 engine which holds an object value and which is updated by | |
| 496 * the garbage collector whenever the object is moved. A new storage | |
| 497 * cell can be created using Persistent::New and existing handles can | |
| 498 * be disposed using Persistent::Dispose. Since persistent handles | |
| 499 * are passed by value you may have many persistent handle objects | |
| 500 * that point to the same storage cell. For instance, if you pass a | |
| 501 * persistent handle as an argument to a function you will not get two | |
| 502 * different storage cells but rather two references to the same | |
| 503 * storage cell. | |
| 504 */ | |
| 505 template <class T> class Persistent // NOLINT | |
| 506 #ifdef V8_USE_UNSAFE_HANDLES | |
| 507 : public Handle<T> { | |
| 508 #else | |
| 509 { // NOLINT | |
| 510 #endif | |
| 511 public: | 453 public: |
| 512 #ifndef V8_USE_UNSAFE_HANDLES | 454 typedef void (*Callback)(WeakCallbackData<T, P>* data); |
| 455 | |
| 456 V8_INLINE(Isolate* GetIsolate()) { return isolate_; } | |
|
Sven Panne
2013/09/05 08:24:09
Constify all the getters! ;-)
| |
| 457 V8_INLINE(Local<T> GetValue()) { return handle_; } | |
| 458 V8_INLINE(P* GetParameter()) { return parameter_; } | |
| 459 | |
| 460 private: | |
| 461 friend class internal::GlobalHandles; | |
| 462 WeakCallbackData(Isolate* isolate, Local<T> handle, P* parameter) | |
| 463 : isolate_(isolate), handle_(handle), parameter_(parameter) { } | |
| 464 Isolate* isolate_; | |
| 465 Local<T> handle_; | |
| 466 P* parameter_; | |
| 467 }; | |
| 468 | |
| 469 | |
| 470 // TODO(dcarney): Remove this class. | |
| 471 template<typename T, | |
| 472 typename P, | |
| 473 typename M = NonCopyablePersistentTraits<T> > | |
| 474 class WeakReferenceCallbacks { | |
| 475 public: | |
| 476 typedef void (*Revivable)(Isolate* isolate, | |
| 477 Persistent<T, M>* object, | |
| 478 P* parameter); | |
| 479 }; | |
| 480 | |
| 481 | |
| 482 // TODO(dcarney): comments | |
| 483 template<class T> | |
| 484 class NonCopyablePersistentTraits { | |
|
marja
2013/08/23 13:02:40
Neat :)
| |
| 485 public: | |
| 486 typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent; | |
| 487 static const bool kDisposeInDestructor = false; | |
| 488 template<class S, class M> | |
| 489 V8_INLINE(static void Copy(const Persistent<S, M>& source, | |
| 490 NonCopyablePersistent* dest)) { | |
| 491 Uncompilable<Object>(); | |
| 492 } | |
| 493 // TODO(dcarney): come up with a good compile error here. | |
| 494 template<class O> | |
| 495 V8_INLINE(static void Uncompilable()) { | |
| 496 TYPE_CHECK(O, Primitive); | |
| 497 } | |
| 498 }; | |
| 499 | |
| 500 | |
| 501 // TODO(dcarney): comments | |
| 502 template <class T, class M> class Persistent { | |
| 503 public: | |
| 504 // normal constructors | |
| 513 V8_INLINE(Persistent()) : val_(0) { } | 505 V8_INLINE(Persistent()) : val_(0) { } |
| 514 // TODO(dcarney): add this back before cutover. | |
| 515 // V8_INLINE(~Persistent()) { | |
| 516 // Dispose(); | |
| 517 // } | |
| 518 V8_INLINE(bool IsEmpty() const) { return val_ == 0; } | |
| 519 // TODO(dcarney): remove somehow before cutover | |
| 520 // The handle should either be 0, or a pointer to a live cell. | |
| 521 V8_INLINE(void Clear()) { val_ = 0; } | |
| 522 | |
| 523 /** | |
| 524 * A constructor that creates a new global cell pointing to that. In contrast | |
| 525 * to the copy constructor, this creates a new persistent handle which needs | |
| 526 * to be separately disposed. | |
| 527 */ | |
| 528 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) | 506 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 529 : val_(New(isolate, *that)) { } | 507 : val_(New(isolate, *that)) { |
| 530 | |
| 531 template <class S> V8_INLINE(Persistent(Isolate* isolate, | |
| 532 const Persistent<S>& that)) // NOLINT | |
| 533 : val_(New(isolate, *that)) { } | |
| 534 | |
| 535 #else | |
| 536 /** | |
| 537 * Creates an empty persistent handle that doesn't point to any | |
| 538 * storage cell. | |
| 539 */ | |
| 540 V8_INLINE(Persistent()) : Handle<T>() { } | |
| 541 | |
| 542 /** | |
| 543 * Creates a persistent handle for the same storage cell as the | |
| 544 * specified handle. This constructor allows you to pass persistent | |
| 545 * handles as arguments by value and to assign between persistent | |
| 546 * handles. However, attempting to assign between incompatible | |
| 547 * persistent handles, for instance from a Persistent<String> to a | |
| 548 * Persistent<Number> will cause a compile-time error. Assigning | |
| 549 * between compatible persistent handles, for instance assigning a | |
| 550 * Persistent<String> to a variable declared as Persistent<Value>, | |
| 551 * is allowed as String is a subclass of Value. | |
| 552 */ | |
| 553 template <class S> V8_INLINE(Persistent(Persistent<S> that)) | |
| 554 : Handle<T>(reinterpret_cast<T*>(*that)) { | |
| 555 /** | |
| 556 * This check fails when trying to convert between incompatible | |
| 557 * handles. For example, converting from a Handle<String> to a | |
| 558 * Handle<Number>. | |
| 559 */ | |
| 560 TYPE_CHECK(T, S); | 508 TYPE_CHECK(T, S); |
| 561 } | 509 } |
| 562 | 510 template <class S, class M2> |
| 563 template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } | 511 V8_INLINE(Persistent(Isolate* isolate, const Persistent<S, M2>& that)) |
| 564 | 512 : val_(New(isolate, *that)) { |
| 565 /** | 513 TYPE_CHECK(T, S); |
| 566 * A constructor that creates a new global cell pointing to that. In contrast | 514 } |
| 567 * to the copy constructor, this creates a new persistent handle which needs | 515 // copy constructor and assignment operators |
| 568 * to be separately disposed. | 516 V8_INLINE(Persistent(const Persistent& that)) : val_(0) { |
| 569 */ | 517 Copy(that); |
| 570 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) | 518 } |
| 571 : Handle<T>(New(isolate, that)) { } | 519 template <class S, class M2> |
| 572 | 520 V8_INLINE(Persistent(const Persistent<S, M2>& that)) : val_(0) { |
| 573 /** | 521 Copy(that); |
| 574 * "Casts" a plain handle which is known to be a persistent handle | 522 } |
| 575 * to a persistent handle. | 523 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 576 */ | 524 Copy(that); |
| 577 template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) | 525 return *this; |
| 578 : Handle<T>(*that) { } | 526 } |
| 579 | 527 template <class S, class M2> |
| 580 #endif | 528 V8_INLINE(Persistent& operator=(const Persistent<S, M2>& that)) { // NOLINT |
| 581 | 529 Copy(that); |
| 582 #ifdef V8_USE_UNSAFE_HANDLES | 530 return *this; |
| 583 template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { | 531 } |
| 584 #ifdef V8_ENABLE_CHECKS | 532 // destructor |
| 585 // If we're going to perform the type check then we have to check | 533 V8_INLINE(~Persistent()) { |
| 586 // that the handle isn't empty before doing the checked cast. | 534 if (M::kDisposeInDestructor) Reset(); |
| 587 if (that.IsEmpty()) return Persistent<T>(); | |
| 588 #endif | |
| 589 return Persistent<T>(T::Cast(*that)); | |
| 590 } | 535 } |
| 591 | 536 |
| 592 template <class S> V8_INLINE(Persistent<S> As()) { | 537 V8_INLINE(void Reset()); |
| 593 return Persistent<S>::Cast(*this); | 538 template <class S> |
| 594 } | 539 V8_INLINE(void Reset(Isolate* isolate, const Handle<S>& other)); |
| 540 template <class S, class M2> | |
| 541 V8_INLINE(void Reset(Isolate* isolate, const Persistent<S, M2>& other)); | |
| 542 // TODO(dcarney): deprecate | |
| 543 V8_INLINE(void Dispose()) { Reset(); } | |
| 544 // TODO(dcarney): deprecate | |
| 545 V8_INLINE(void Dispose(Isolate* isolate)) { Reset(); } | |
| 595 | 546 |
| 596 #else | 547 V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 548 | |
| 549 // TODO(dcarney): this is pretty useless, fix or remove | |
| 597 template <class S> | 550 template <class S> |
| 598 V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT | 551 V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT |
| 599 #ifdef V8_ENABLE_CHECKS | 552 #ifdef V8_ENABLE_CHECKS |
| 600 // If we're going to perform the type check then we have to check | 553 // If we're going to perform the type check then we have to check |
| 601 // that the handle isn't empty before doing the checked cast. | 554 // that the handle isn't empty before doing the checked cast. |
| 602 if (!that.IsEmpty()) T::Cast(*that); | 555 if (!that.IsEmpty()) T::Cast(*that); |
| 603 #endif | 556 #endif |
| 604 return reinterpret_cast<Persistent<T>&>(that); | 557 return reinterpret_cast<Persistent<T>&>(that); |
| 605 } | 558 } |
| 606 | 559 |
| 560 // TODO(dcarney): this is pretty useless, fix or remove | |
| 607 template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT | 561 template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT |
| 608 return Persistent<S>::Cast(*this); | 562 return Persistent<S>::Cast(*this); |
| 609 } | 563 } |
| 610 #endif | |
| 611 | 564 |
| 612 #ifdef V8_USE_UNSAFE_HANDLES | 565 template <class S, class M2> V8_INLINE( |
| 613 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); | 566 bool operator==(const Persistent<S, M2>& that) const) { |
| 614 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); | |
| 615 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); | |
| 616 #endif | |
| 617 | |
| 618 #ifndef V8_USE_UNSAFE_HANDLES | |
| 619 template <class S> V8_INLINE( | |
| 620 bool operator==(const Persistent<S>& that) const) { | |
| 621 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 567 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 622 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 568 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 623 if (a == 0) return b == 0; | 569 if (a == 0) return b == 0; |
| 624 if (b == 0) return false; | 570 if (b == 0) return false; |
| 625 return *a == *b; | 571 return *a == *b; |
| 626 } | 572 } |
| 627 | 573 |
| 628 template <class S> V8_INLINE(bool operator==(const Handle<S>& that) const) { | 574 template <class S> V8_INLINE(bool operator==(const Handle<S>& that) const) { |
| 629 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 575 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 630 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 576 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 631 if (a == 0) return b == 0; | 577 if (a == 0) return b == 0; |
| 632 if (b == 0) return false; | 578 if (b == 0) return false; |
| 633 return *a == *b; | 579 return *a == *b; |
| 634 } | 580 } |
| 635 | 581 |
| 636 template <class S> V8_INLINE( | 582 template <class S, class M2> V8_INLINE( |
| 637 bool operator!=(const Persistent<S>& that) const) { | 583 bool operator!=(const Persistent<S, M2>& that) const) { |
| 638 return !operator==(that); | 584 return !operator==(that); |
| 639 } | 585 } |
| 640 | 586 |
| 641 template <class S> V8_INLINE(bool operator!=(const Handle<S>& that) const) { | 587 template <class S> V8_INLINE(bool operator!=(const Handle<S>& that) const) { |
| 642 return !operator==(that); | 588 return !operator==(that); |
| 643 } | 589 } |
| 644 #endif | |
| 645 | |
| 646 V8_INLINE(void Dispose()); | |
| 647 | |
| 648 /** | |
| 649 * Releases the storage cell referenced by this persistent handle. | |
| 650 * Does not remove the reference to the cell from any handles. | |
| 651 * This handle's reference, and any other references to the storage | |
| 652 * cell remain and IsEmpty will still return false. | |
| 653 */ | |
| 654 // TODO(dcarney): deprecate | |
| 655 V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); } | |
| 656 | |
| 657 /** | |
| 658 * Make the reference to this object weak. When only weak handles | |
| 659 * refer to the object, the garbage collector will perform a | |
| 660 * callback to the given V8::NearDeathCallback function, passing | |
| 661 * it the object reference and the given parameters. | |
| 662 */ | |
| 663 template<typename S, typename P> | |
| 664 V8_INLINE(void MakeWeak( | |
| 665 P* parameters, | |
| 666 typename WeakReferenceCallbacks<S, P>::Revivable callback)); | |
| 667 | 590 |
| 668 template<typename P> | 591 template<typename P> |
| 669 V8_INLINE(void MakeWeak( | 592 V8_INLINE(void MakeWeak( |
| 670 P* parameters, | 593 P* parameter, |
| 671 typename WeakReferenceCallbacks<T, P>::Revivable callback)); | 594 typename WeakCallbackData<T, P>::Callback callback)); |
| 672 | 595 |
| 673 template<typename S, typename P> | 596 template<typename S, typename P> |
| 674 V8_DEPRECATED(void MakeWeak( | 597 V8_INLINE(void MakeWeak( |
| 675 Isolate* isolate, | 598 P* parameter, |
| 676 P* parameters, | 599 typename WeakCallbackData<S, P>::Callback callback)); |
| 600 | |
| 601 // TODO(dcarney): deprecate | |
| 602 template<typename S, typename P> | |
| 603 V8_INLINE(void MakeWeak( | |
| 604 P* parameter, | |
| 677 typename WeakReferenceCallbacks<S, P>::Revivable callback)); | 605 typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 678 | 606 |
| 607 // TODO(dcarney): deprecate | |
| 679 template<typename P> | 608 template<typename P> |
| 680 V8_DEPRECATED(void MakeWeak( | 609 V8_INLINE(void MakeWeak( |
| 681 Isolate* isolate, | 610 P* parameter, |
| 682 P* parameters, | |
| 683 typename WeakReferenceCallbacks<T, P>::Revivable callback)); | 611 typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| 684 | 612 |
| 685 V8_INLINE(void ClearWeak()); | 613 V8_INLINE(void ClearWeak()); |
| 686 | 614 |
| 687 // TODO(dcarney): deprecate | 615 // TODO(dcarney): deprecate |
| 688 V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } | 616 V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } |
| 689 | 617 |
| 690 /** | 618 /** |
| 691 * Marks the reference to this object independent. Garbage collector is free | 619 * Marks the reference to this object independent. Garbage collector is free |
| 692 * to ignore any object groups containing this object. Weak callback for an | 620 * to ignore any object groups containing this object. Weak callback for an |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 * Returns the class ID previously assigned to this handle or 0 if no class ID | 675 * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 748 * was previously assigned. | 676 * was previously assigned. |
| 749 */ | 677 */ |
| 750 V8_INLINE(uint16_t WrapperClassId() const); | 678 V8_INLINE(uint16_t WrapperClassId() const); |
| 751 | 679 |
| 752 // TODO(dcarney): deprecate | 680 // TODO(dcarney): deprecate |
| 753 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { | 681 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { |
| 754 return WrapperClassId(); | 682 return WrapperClassId(); |
| 755 } | 683 } |
| 756 | 684 |
| 757 /** | 685 // TODO(dcarney): remove |
| 758 * Disposes the current contents of the handle and replaces it. | |
| 759 */ | |
| 760 V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); | |
| 761 | |
| 762 #ifndef V8_USE_UNSAFE_HANDLES | |
| 763 V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other)); | |
| 764 #endif | |
| 765 | |
| 766 /** | |
| 767 * Returns the underlying raw pointer and clears the handle. The caller is | |
| 768 * responsible of eventually destroying the underlying object (by creating a | |
| 769 * Persistent handle which points to it and Disposing it). In the future, | |
| 770 * destructing a Persistent will also Dispose it. With this function, the | |
| 771 * embedder can let the Persistent go out of scope without it getting | |
| 772 * disposed. | |
| 773 */ | |
| 774 V8_INLINE(T* ClearAndLeak()); | 686 V8_INLINE(T* ClearAndLeak()); |
| 775 | 687 |
| 776 #ifndef V8_USE_UNSAFE_HANDLES | 688 // TODO(dcarney) make private or remove |
| 689 // Only the garbage collector should do this, | |
| 690 // and it can just change val_ directly | |
| 691 // could temporarily just assert that the node is disposed | |
| 692 V8_INLINE(void Clear()) { val_ = 0; } | |
| 777 | 693 |
| 778 private: | 694 // TODO(dcarney): remove need for this in chrome |
| 779 // TODO(dcarney): make unlinkable before cutover | |
| 780 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} | |
| 781 // TODO(dcarney): make unlinkable before cutover | |
| 782 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT | |
| 783 this->val_ = that.val_; | |
| 784 return *this; | |
| 785 } | |
| 786 | |
| 787 public: | |
| 788 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 695 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 789 | 696 |
| 790 private: | 697 private: |
| 791 #endif | 698 #endif |
| 792 // TODO(dcarney): remove before cutover | |
| 793 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } | 699 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 794 | 700 |
| 795 // TODO(dcarney): remove before cutover | |
| 796 V8_INLINE(T* operator*() const) { return val_; } | 701 V8_INLINE(T* operator*() const) { return val_; } |
| 797 | 702 |
| 798 private: | 703 private: |
| 799 // TODO(dcarney): remove before cutover | |
| 800 V8_INLINE(T* operator->() const) { return val_; } | |
| 801 public: | |
| 802 #endif | |
| 803 | |
| 804 private: | |
| 805 friend class Utils; | 704 friend class Utils; |
| 806 template<class F> friend class Handle; | 705 template<class F> friend class Handle; |
| 807 template<class F> friend class Local; | 706 template<class F> friend class Local; |
| 808 template<class F> friend class Persistent; | 707 template<class F1, class F2> friend class Persistent; |
| 809 template<class F> friend class ReturnValue; | 708 template<class F> friend class ReturnValue; |
| 810 | 709 |
| 811 V8_INLINE(static T* New(Isolate* isolate, T* that)); | 710 V8_INLINE(static T* New(Isolate* isolate, T* that)); |
| 711 template<class S, class M2> | |
| 712 V8_INLINE(void Copy(const Persistent<S, M2>& that)); | |
| 812 | 713 |
| 813 #ifndef V8_USE_UNSAFE_HANDLES | |
| 814 T* val_; | 714 T* val_; |
| 815 #endif | |
| 816 }; | 715 }; |
| 817 | 716 |
| 818 | |
| 819 /** | 717 /** |
| 820 * A stack-allocated class that governs a number of local handles. | 718 * A stack-allocated class that governs a number of local handles. |
| 821 * After a handle scope has been created, all local handles will be | 719 * After a handle scope has been created, all local handles will be |
| 822 * allocated within that handle scope until either the handle scope is | 720 * allocated within that handle scope until either the handle scope is |
| 823 * deleted or another handle scope is created. If there is already a | 721 * deleted or another handle scope is created. If there is already a |
| 824 * handle scope and a new one is created, all allocations will take | 722 * handle scope and a new one is created, all allocations will take |
| 825 * place in the new handle scope until it is deleted. After that, | 723 * place in the new handle scope until it is deleted. After that, |
| 826 * new handles will again be allocated in the original handle scope. | 724 * new handles will again be allocated in the original handle scope. |
| 827 * | 725 * |
| 828 * After the handle scope of a local handle has been deleted the | 726 * After the handle scope of a local handle has been deleted the |
| (...skipping 3971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4800 * Initialize the ICU library bundled with V8. The embedder should only | 4698 * Initialize the ICU library bundled with V8. The embedder should only |
| 4801 * invoke this method when using the bundled ICU. Returns true on success. | 4699 * invoke this method when using the bundled ICU. Returns true on success. |
| 4802 */ | 4700 */ |
| 4803 static bool InitializeICU(); | 4701 static bool InitializeICU(); |
| 4804 | 4702 |
| 4805 private: | 4703 private: |
| 4806 V8(); | 4704 V8(); |
| 4807 | 4705 |
| 4808 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 4706 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4809 internal::Object** handle); | 4707 internal::Object** handle); |
| 4708 static internal::Object** CopyPersistent(internal::Object** handle); | |
|
marja
2013/08/23 13:02:40
This creates another legit Persistent for the same
| |
| 4810 static void DisposeGlobal(internal::Object** global_handle); | 4709 static void DisposeGlobal(internal::Object** global_handle); |
| 4811 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; | 4710 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
| 4711 typedef WeakCallbackData<Value, void>::Callback WeakCallback; | |
| 4812 static void MakeWeak(internal::Object** global_handle, | 4712 static void MakeWeak(internal::Object** global_handle, |
| 4813 void* data, | 4713 void* data, |
| 4714 WeakCallback weak_callback, | |
| 4814 RevivableCallback weak_reference_callback); | 4715 RevivableCallback weak_reference_callback); |
| 4815 static void ClearWeak(internal::Object** global_handle); | 4716 static void ClearWeak(internal::Object** global_handle); |
| 4816 static int Eternalize(internal::Isolate* isolate, | 4717 static int Eternalize(internal::Isolate* isolate, |
| 4817 internal::Object** handle); | 4718 internal::Object** handle); |
| 4818 static internal::Object** GetEternal(internal::Isolate* isolate, int index); | 4719 static internal::Object** GetEternal(internal::Isolate* isolate, int index); |
| 4819 | 4720 |
| 4820 template <class T> friend class Handle; | 4721 template <class T> friend class Handle; |
| 4821 template <class T> friend class Local; | 4722 template <class T> friend class Local; |
| 4822 template <class T> friend class Persistent; | 4723 template <class T, class M> friend class Persistent; |
| 4823 friend class Context; | 4724 friend class Context; |
| 4824 }; | 4725 }; |
| 4825 | 4726 |
| 4826 | 4727 |
| 4827 /** | 4728 /** |
| 4828 * An external exception handler. | 4729 * An external exception handler. |
| 4829 */ | 4730 */ |
| 4830 class V8_EXPORT TryCatch { | 4731 class V8_EXPORT TryCatch { |
| 4831 public: | 4732 public: |
| 4832 /** | 4733 /** |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5153 * Stack-allocated class which sets the execution context for all | 5054 * Stack-allocated class which sets the execution context for all |
| 5154 * operations executed within a local scope. | 5055 * operations executed within a local scope. |
| 5155 */ | 5056 */ |
| 5156 class Scope { | 5057 class Scope { |
| 5157 public: | 5058 public: |
| 5158 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { | 5059 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
| 5159 context_->Enter(); | 5060 context_->Enter(); |
| 5160 } | 5061 } |
| 5161 // TODO(dcarney): deprecate | 5062 // TODO(dcarney): deprecate |
| 5162 V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT | 5063 V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 5163 #ifndef V8_USE_UNSAFE_HANDLES | |
| 5164 : context_(Handle<Context>::New(isolate, context)) { | 5064 : context_(Handle<Context>::New(isolate, context)) { |
| 5165 #else | |
| 5166 : context_(Local<Context>::New(isolate, context)) { | |
| 5167 #endif | |
| 5168 context_->Enter(); | 5065 context_->Enter(); |
| 5169 } | 5066 } |
| 5170 V8_INLINE(~Scope()) { context_->Exit(); } | 5067 V8_INLINE(~Scope()) { context_->Exit(); } |
| 5171 | 5068 |
| 5172 private: | 5069 private: |
| 5173 Handle<Context> context_; | 5070 Handle<Context> context_; |
| 5174 }; | 5071 }; |
| 5175 | 5072 |
| 5176 private: | 5073 private: |
| 5177 friend class Value; | 5074 friend class Value; |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5645 } | 5542 } |
| 5646 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | 5543 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5647 } | 5544 } |
| 5648 | 5545 |
| 5649 | 5546 |
| 5650 template <class T> | 5547 template <class T> |
| 5651 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | 5548 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
| 5652 return New(isolate, that.val_); | 5549 return New(isolate, that.val_); |
| 5653 } | 5550 } |
| 5654 | 5551 |
| 5655 #ifndef V8_USE_UNSAFE_HANDLES | |
| 5656 template <class T> | 5552 template <class T> |
| 5657 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { | 5553 template <class M> |
| 5554 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { | |
| 5658 return New(isolate, that.val_); | 5555 return New(isolate, that.val_); |
| 5659 } | 5556 } |
| 5660 | 5557 |
| 5661 template <class T> | 5558 template <class T> |
| 5662 Handle<T> Handle<T>::New(Isolate* isolate, T* that) { | 5559 Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5663 if (that == NULL) return Handle<T>(); | 5560 if (that == NULL) return Handle<T>(); |
| 5664 T* that_ptr = that; | 5561 T* that_ptr = that; |
| 5665 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 5562 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5666 return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 5563 return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5667 reinterpret_cast<internal::Isolate*>(isolate), *p))); | 5564 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5668 } | 5565 } |
| 5669 #endif | |
| 5670 | 5566 |
| 5671 | 5567 |
| 5672 template <class T> | 5568 template <class T> |
| 5673 Local<T> Local<T>::New(Isolate* isolate, T* that) { | 5569 Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5674 if (that == NULL) return Local<T>(); | 5570 if (that == NULL) return Local<T>(); |
| 5675 T* that_ptr = that; | 5571 T* that_ptr = that; |
| 5676 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 5572 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5677 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 5573 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5678 reinterpret_cast<internal::Isolate*>(isolate), *p))); | 5574 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5679 } | 5575 } |
| 5680 | 5576 |
| 5681 | 5577 |
| 5682 template<class T> | 5578 template<class T> |
| 5683 int Local<T>::Eternalize(Isolate* isolate) { | 5579 int Local<T>::Eternalize(Isolate* isolate) { |
| 5684 return V8::Eternalize(reinterpret_cast<internal::Isolate*>(isolate), | 5580 return V8::Eternalize(reinterpret_cast<internal::Isolate*>(isolate), |
| 5685 reinterpret_cast<internal::Object**>(this->val_)); | 5581 reinterpret_cast<internal::Object**>(this->val_)); |
| 5686 } | 5582 } |
| 5687 | 5583 |
| 5688 | 5584 |
| 5689 template<class T> | 5585 template<class T> |
| 5690 Local<T> Local<T>::GetEternal(Isolate* isolate, int index) { | 5586 Local<T> Local<T>::GetEternal(Isolate* isolate, int index) { |
| 5691 internal::Object** handle = | 5587 internal::Object** handle = |
| 5692 V8::GetEternal(reinterpret_cast<internal::Isolate*>(isolate), index); | 5588 V8::GetEternal(reinterpret_cast<internal::Isolate*>(isolate), index); |
| 5693 return Local<T>(T::Cast(reinterpret_cast<Value*>(handle))); | 5589 return Local<T>(T::Cast(reinterpret_cast<Value*>(handle))); |
| 5694 } | 5590 } |
| 5695 | 5591 |
| 5696 | 5592 |
| 5697 #ifdef V8_USE_UNSAFE_HANDLES | 5593 template <class T, class M> |
| 5698 template <class T> | 5594 T* Persistent<T, M>::New(Isolate* isolate, T* that) { |
| 5699 Persistent<T> Persistent<T>::New(Handle<T> that) { | |
| 5700 return New(Isolate::GetCurrent(), that.val_); | |
| 5701 } | |
| 5702 | |
| 5703 | |
| 5704 template <class T> | |
| 5705 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { | |
| 5706 return New(Isolate::GetCurrent(), that.val_); | |
| 5707 } | |
| 5708 | |
| 5709 template <class T> | |
| 5710 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { | |
| 5711 return New(Isolate::GetCurrent(), that.val_); | |
| 5712 } | |
| 5713 #endif | |
| 5714 | |
| 5715 | |
| 5716 template <class T> | |
| 5717 T* Persistent<T>::New(Isolate* isolate, T* that) { | |
| 5718 if (that == NULL) return NULL; | 5595 if (that == NULL) return NULL; |
| 5719 internal::Object** p = reinterpret_cast<internal::Object**>(that); | 5596 internal::Object** p = reinterpret_cast<internal::Object**>(that); |
| 5720 return reinterpret_cast<T*>( | 5597 return reinterpret_cast<T*>( |
| 5721 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | 5598 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5722 p)); | 5599 p)); |
| 5723 } | 5600 } |
| 5724 | 5601 |
| 5725 | 5602 |
| 5726 template <class T> | 5603 template <class T, class M> |
| 5727 bool Persistent<T>::IsIndependent() const { | 5604 template <class S, class M2> |
| 5605 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { | |
| 5606 TYPE_CHECK(T, S); | |
| 5607 Reset(); | |
| 5608 if (that.IsEmpty()) return; | |
| 5609 internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); | |
| 5610 this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); | |
| 5611 M::Copy(that, this); | |
| 5612 } | |
| 5613 | |
| 5614 | |
| 5615 template <class T, class M> | |
| 5616 bool Persistent<T, M>::IsIndependent() const { | |
| 5728 typedef internal::Internals I; | 5617 typedef internal::Internals I; |
| 5729 if (this->IsEmpty()) return false; | 5618 if (this->IsEmpty()) return false; |
| 5730 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5619 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 5731 I::kNodeIsIndependentShift); | 5620 I::kNodeIsIndependentShift); |
| 5732 } | 5621 } |
| 5733 | 5622 |
| 5734 | 5623 |
| 5735 template <class T> | 5624 template <class T, class M> |
| 5736 bool Persistent<T>::IsNearDeath() const { | 5625 bool Persistent<T, M>::IsNearDeath() const { |
| 5737 typedef internal::Internals I; | 5626 typedef internal::Internals I; |
| 5738 if (this->IsEmpty()) return false; | 5627 if (this->IsEmpty()) return false; |
| 5739 uint8_t node_state = | 5628 uint8_t node_state = |
| 5740 I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)); | 5629 I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)); |
| 5741 return node_state == I::kNodeStateIsNearDeathValue || | 5630 return node_state == I::kNodeStateIsNearDeathValue || |
| 5742 node_state == I::kNodeStateIsPendingValue; | 5631 node_state == I::kNodeStateIsPendingValue; |
| 5743 } | 5632 } |
| 5744 | 5633 |
| 5745 | 5634 |
| 5746 template <class T> | 5635 template <class T, class M> |
| 5747 bool Persistent<T>::IsWeak() const { | 5636 bool Persistent<T, M>::IsWeak() const { |
| 5748 typedef internal::Internals I; | 5637 typedef internal::Internals I; |
| 5749 if (this->IsEmpty()) return false; | 5638 if (this->IsEmpty()) return false; |
| 5750 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | 5639 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
| 5751 I::kNodeStateIsWeakValue; | 5640 I::kNodeStateIsWeakValue; |
| 5752 } | 5641 } |
| 5753 | 5642 |
| 5754 | 5643 |
| 5755 template <class T> | 5644 template <class T, class M> |
| 5756 void Persistent<T>::Dispose() { | 5645 void Persistent<T, M>::Reset() { |
| 5757 if (this->IsEmpty()) return; | 5646 if (this->IsEmpty()) return; |
| 5758 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); | 5647 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); |
| 5759 #ifndef V8_USE_UNSAFE_HANDLES | |
| 5760 val_ = 0; | 5648 val_ = 0; |
| 5761 #endif | |
| 5762 } | 5649 } |
| 5763 | 5650 |
| 5764 | 5651 |
| 5765 template <class T> | 5652 template <class T, class M> |
| 5653 template <class S> | |
| 5654 void Persistent<T, M>::Reset(Isolate* isolate, const Handle<S>& other) { | |
| 5655 TYPE_CHECK(T, S); | |
| 5656 Reset(); | |
| 5657 if (other.IsEmpty()) return; | |
| 5658 this->val_ = New(isolate, other.val_); | |
| 5659 } | |
| 5660 | |
| 5661 | |
| 5662 template <class T, class M> | |
| 5663 template <class S, class M2> | |
| 5664 void Persistent<T, M>::Reset(Isolate* isolate, | |
| 5665 const Persistent<S, M2>& other) { | |
| 5666 TYPE_CHECK(T, S); | |
| 5667 Reset(); | |
| 5668 if (other.IsEmpty()) return; | |
| 5669 this->val_ = New(isolate, other.val_); | |
| 5670 } | |
| 5671 | |
| 5672 | |
| 5673 template <class T, class M> | |
| 5766 template <typename S, typename P> | 5674 template <typename S, typename P> |
| 5767 void Persistent<T>::MakeWeak( | 5675 void Persistent<T, M>::MakeWeak( |
| 5676 P* parameter, | |
| 5677 typename WeakCallbackData<S, P>::Callback callback) { | |
| 5678 TYPE_CHECK(S, T); | |
| 5679 typedef typename WeakCallbackData<Value, void>::Callback Callback; | |
| 5680 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | |
| 5681 parameter, | |
| 5682 reinterpret_cast<Callback>(callback), | |
| 5683 NULL); | |
| 5684 } | |
| 5685 | |
| 5686 | |
| 5687 template <class T, class M> | |
| 5688 template <typename P> | |
| 5689 void Persistent<T, M>::MakeWeak( | |
| 5690 P* parameter, | |
| 5691 typename WeakCallbackData<T, P>::Callback callback) { | |
| 5692 MakeWeak<T, P>(parameter, callback); | |
| 5693 } | |
| 5694 | |
| 5695 | |
| 5696 template <class T, class M> | |
| 5697 template <typename S, typename P> | |
| 5698 void Persistent<T, M>::MakeWeak( | |
| 5768 P* parameters, | 5699 P* parameters, |
| 5769 typename WeakReferenceCallbacks<S, P>::Revivable callback) { | 5700 typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5770 TYPE_CHECK(S, T); | 5701 TYPE_CHECK(S, T); |
| 5771 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; | 5702 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
| 5772 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | 5703 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
| 5773 parameters, | 5704 parameters, |
| 5705 NULL, | |
| 5774 reinterpret_cast<Revivable>(callback)); | 5706 reinterpret_cast<Revivable>(callback)); |
| 5775 } | 5707 } |
| 5776 | 5708 |
| 5777 | 5709 |
| 5778 template <class T> | 5710 template <class T, class M> |
| 5779 template <typename P> | 5711 template <typename P> |
| 5780 void Persistent<T>::MakeWeak( | 5712 void Persistent<T, M>::MakeWeak( |
| 5781 P* parameters, | 5713 P* parameters, |
| 5782 typename WeakReferenceCallbacks<T, P>::Revivable callback) { | 5714 typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5783 MakeWeak<T, P>(parameters, callback); | 5715 MakeWeak<T, P>(parameters, callback); |
| 5784 } | 5716 } |
| 5785 | 5717 |
| 5786 | 5718 |
| 5787 template <class T> | 5719 template <class T, class M> |
| 5788 template <typename S, typename P> | 5720 void Persistent<T, M>::ClearWeak() { |
| 5789 void Persistent<T>::MakeWeak( | |
| 5790 Isolate* isolate, | |
| 5791 P* parameters, | |
| 5792 typename WeakReferenceCallbacks<S, P>::Revivable callback) { | |
| 5793 MakeWeak<S, P>(parameters, callback); | |
| 5794 } | |
| 5795 | |
| 5796 | |
| 5797 template <class T> | |
| 5798 template<typename P> | |
| 5799 void Persistent<T>::MakeWeak( | |
| 5800 Isolate* isolate, | |
| 5801 P* parameters, | |
| 5802 typename WeakReferenceCallbacks<T, P>::Revivable callback) { | |
| 5803 MakeWeak<P>(parameters, callback); | |
| 5804 } | |
| 5805 | |
| 5806 | |
| 5807 template <class T> | |
| 5808 void Persistent<T>::ClearWeak() { | |
| 5809 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | 5721 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
| 5810 } | 5722 } |
| 5811 | 5723 |
| 5812 | 5724 |
| 5813 template <class T> | 5725 template <class T, class M> |
| 5814 void Persistent<T>::MarkIndependent() { | 5726 void Persistent<T, M>::MarkIndependent() { |
| 5815 typedef internal::Internals I; | 5727 typedef internal::Internals I; |
| 5816 if (this->IsEmpty()) return; | 5728 if (this->IsEmpty()) return; |
| 5817 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5729 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 5818 true, | 5730 true, |
| 5819 I::kNodeIsIndependentShift); | 5731 I::kNodeIsIndependentShift); |
| 5820 } | 5732 } |
| 5821 | 5733 |
| 5822 | 5734 |
| 5823 template <class T> | 5735 template <class T, class M> |
| 5824 void Persistent<T>::MarkPartiallyDependent() { | 5736 void Persistent<T, M>::MarkPartiallyDependent() { |
| 5825 typedef internal::Internals I; | 5737 typedef internal::Internals I; |
| 5826 if (this->IsEmpty()) return; | 5738 if (this->IsEmpty()) return; |
| 5827 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5739 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 5828 true, | 5740 true, |
| 5829 I::kNodeIsPartiallyDependentShift); | 5741 I::kNodeIsPartiallyDependentShift); |
| 5830 } | 5742 } |
| 5831 | 5743 |
| 5832 | 5744 |
| 5833 template <class T> | 5745 template <class T, class M> |
| 5834 void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { | 5746 T* Persistent<T, M>::ClearAndLeak() { |
| 5835 Dispose(isolate); | |
| 5836 #ifdef V8_USE_UNSAFE_HANDLES | |
| 5837 *this = *New(isolate, other); | |
| 5838 #else | |
| 5839 if (other.IsEmpty()) { | |
| 5840 this->val_ = NULL; | |
| 5841 return; | |
| 5842 } | |
| 5843 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | |
| 5844 this->val_ = reinterpret_cast<T*>( | |
| 5845 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); | |
| 5846 #endif | |
| 5847 } | |
| 5848 | |
| 5849 | |
| 5850 #ifndef V8_USE_UNSAFE_HANDLES | |
| 5851 template <class T> | |
| 5852 void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) { | |
| 5853 Dispose(isolate); | |
| 5854 if (other.IsEmpty()) { | |
| 5855 this->val_ = NULL; | |
| 5856 return; | |
| 5857 } | |
| 5858 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | |
| 5859 this->val_ = reinterpret_cast<T*>( | |
| 5860 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); | |
| 5861 } | |
| 5862 #endif | |
| 5863 | |
| 5864 | |
| 5865 template <class T> | |
| 5866 T* Persistent<T>::ClearAndLeak() { | |
| 5867 T* old; | 5747 T* old; |
| 5868 #ifdef V8_USE_UNSAFE_HANDLES | |
| 5869 old = **this; | |
| 5870 *this = Persistent<T>(); | |
| 5871 #else | |
| 5872 old = val_; | 5748 old = val_; |
| 5873 val_ = NULL; | 5749 val_ = NULL; |
| 5874 #endif | |
| 5875 return old; | 5750 return old; |
| 5876 } | 5751 } |
| 5877 | 5752 |
| 5878 | 5753 |
| 5879 template <class T> | 5754 template <class T, class M> |
| 5880 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | 5755 void Persistent<T, M>::SetWrapperClassId(uint16_t class_id) { |
| 5881 typedef internal::Internals I; | 5756 typedef internal::Internals I; |
| 5882 if (this->IsEmpty()) return; | 5757 if (this->IsEmpty()) return; |
| 5883 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); | 5758 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
| 5884 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5759 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5885 *reinterpret_cast<uint16_t*>(addr) = class_id; | 5760 *reinterpret_cast<uint16_t*>(addr) = class_id; |
| 5886 } | 5761 } |
| 5887 | 5762 |
| 5888 | 5763 |
| 5889 template <class T> | 5764 template <class T, class M> |
| 5890 uint16_t Persistent<T>::WrapperClassId() const { | 5765 uint16_t Persistent<T, M>::WrapperClassId() const { |
| 5891 typedef internal::Internals I; | 5766 typedef internal::Internals I; |
| 5892 if (this->IsEmpty()) return 0; | 5767 if (this->IsEmpty()) return 0; |
| 5893 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); | 5768 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
| 5894 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5769 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5895 return *reinterpret_cast<uint16_t*>(addr); | 5770 return *reinterpret_cast<uint16_t*>(addr); |
| 5896 } | 5771 } |
| 5897 | 5772 |
| 5898 | 5773 |
| 5899 template<typename T> | 5774 template<typename T> |
| 5900 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | 5775 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6602 */ | 6477 */ |
| 6603 | 6478 |
| 6604 | 6479 |
| 6605 } // namespace v8 | 6480 } // namespace v8 |
| 6606 | 6481 |
| 6607 | 6482 |
| 6608 #undef TYPE_CHECK | 6483 #undef TYPE_CHECK |
| 6609 | 6484 |
| 6610 | 6485 |
| 6611 #endif // V8_H_ | 6486 #endif // V8_H_ |
| OLD | NEW |