| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 * | 152 * |
| 153 * There are two types of handles: local and persistent handles. | 153 * There are two types of handles: local and persistent handles. |
| 154 * Local handles are light-weight and transient and typically used in | 154 * Local handles are light-weight and transient and typically used in |
| 155 * local operations. They are managed by HandleScopes. Persistent | 155 * local operations. They are managed by HandleScopes. Persistent |
| 156 * handles can be used when storing objects across several independent | 156 * handles can be used when storing objects across several independent |
| 157 * operations and have to be explicitly deallocated when they're no | 157 * operations and have to be explicitly deallocated when they're no |
| 158 * longer used. | 158 * longer used. |
| 159 * | 159 * |
| 160 * It is safe to extract the object stored in the handle by | 160 * It is safe to extract the object stored in the handle by |
| 161 * dereferencing the handle (for instance, to extract the Object* from | 161 * dereferencing the handle (for instance, to extract the Object* from |
| 162 * an Handle<Object>); the value will still be governed by a handle | 162 * a Handle<Object>); the value will still be governed by a handle |
| 163 * behind the scenes and the same rules apply to these values as to | 163 * behind the scenes and the same rules apply to these values as to |
| 164 * their handles. | 164 * their handles. |
| 165 */ | 165 */ |
| 166 template <class T> class Handle { | 166 template <class T> class Handle { |
| 167 public: | 167 public: |
| 168 | 168 |
| 169 /** | 169 /** |
| 170 * Creates an empty handle. | 170 * Creates an empty handle. |
| 171 */ | 171 */ |
| 172 inline Handle(); | 172 inline Handle(); |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * Creates a new handle for the specified value. | 175 * Creates a new handle for the specified value. |
| 176 */ | 176 */ |
| 177 inline explicit Handle(T* val) : val_(val) { } | 177 inline explicit Handle(T* val) : val_(val) { } |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * Creates a handle for the contents of the specified handle. This | 180 * Creates a handle for the contents of the specified handle. This |
| 181 * constructor allows you to pass handles as arguments by value and | 181 * constructor allows you to pass handles as arguments by value and |
| 182 * to assign between handles. However, if you try to assign between | 182 * to assign between handles. However, if you try to assign between |
| 183 * incompatible handles, for instance from a Handle<String> to a | 183 * incompatible handles, for instance from a Handle<String> to a |
| 184 * Handle<Number> it will cause a compiletime error. Assigning | 184 * Handle<Number> it will cause a compile-time error. Assigning |
| 185 * between compatible handles, for instance assigning a | 185 * between compatible handles, for instance assigning a |
| 186 * Handle<String> to a variable declared as Handle<Value>, is legal | 186 * Handle<String> to a variable declared as Handle<Value>, is legal |
| 187 * because String is a subclass of Value. | 187 * because String is a subclass of Value. |
| 188 */ | 188 */ |
| 189 template <class S> inline Handle(Handle<S> that) | 189 template <class S> inline Handle(Handle<S> that) |
| 190 : val_(reinterpret_cast<T*>(*that)) { | 190 : val_(reinterpret_cast<T*>(*that)) { |
| 191 /** | 191 /** |
| 192 * This check fails when trying to convert between incompatible | 192 * This check fails when trying to convert between incompatible |
| 193 * handles. For example, converting from a Handle<String> to a | 193 * handles. For example, converting from a Handle<String> to a |
| 194 * Handle<Number>. | 194 * Handle<Number>. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 * storage cell. | 318 * storage cell. |
| 319 */ | 319 */ |
| 320 inline Persistent(); | 320 inline Persistent(); |
| 321 | 321 |
| 322 /** | 322 /** |
| 323 * Creates a persistent handle for the same storage cell as the | 323 * Creates a persistent handle for the same storage cell as the |
| 324 * specified handle. This constructor allows you to pass persistent | 324 * specified handle. This constructor allows you to pass persistent |
| 325 * handles as arguments by value and to assign between persistent | 325 * handles as arguments by value and to assign between persistent |
| 326 * handles. However, attempting to assign between incompatible | 326 * handles. However, attempting to assign between incompatible |
| 327 * persistent handles, for instance from a Persistent<String> to a | 327 * persistent handles, for instance from a Persistent<String> to a |
| 328 * Persistent<Number> will cause a compiletime error. Assigning | 328 * Persistent<Number> will cause a compile-time error. Assigning |
| 329 * between compatible persistent handles, for instance assigning a | 329 * between compatible persistent handles, for instance assigning a |
| 330 * Persistent<String> to a variable declared as Persistent<Value>, | 330 * Persistent<String> to a variable declared as Persistent<Value>, |
| 331 * is allowed as String is a subclass of Value. | 331 * is allowed as String is a subclass of Value. |
| 332 */ | 332 */ |
| 333 template <class S> inline Persistent(Persistent<S> that) | 333 template <class S> inline Persistent(Persistent<S> that) |
| 334 : Handle<T>(reinterpret_cast<T*>(*that)) { | 334 : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 335 /** | 335 /** |
| 336 * This check fails when trying to convert between incompatible | 336 * This check fails when trying to convert between incompatible |
| 337 * handles. For example, converting from a Handle<String> to a | 337 * handles. For example, converting from a Handle<String> to a |
| 338 * Handle<Number>. | 338 * Handle<Number>. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 364 | 364 |
| 365 /** | 365 /** |
| 366 * Creates a new persistent handle for an existing local or | 366 * Creates a new persistent handle for an existing local or |
| 367 * persistent handle. | 367 * persistent handle. |
| 368 */ | 368 */ |
| 369 inline static Persistent<T> New(Handle<T> that); | 369 inline static Persistent<T> New(Handle<T> that); |
| 370 | 370 |
| 371 /** | 371 /** |
| 372 * Releases the storage cell referenced by this persistent handle. | 372 * Releases the storage cell referenced by this persistent handle. |
| 373 * Does not remove the reference to the cell from any handles. | 373 * Does not remove the reference to the cell from any handles. |
| 374 * This handle's reference, and any any other references to the storage | 374 * This handle's reference, and any other references to the storage |
| 375 * cell remain and IsEmpty will still return false. | 375 * cell remain and IsEmpty will still return false. |
| 376 */ | 376 */ |
| 377 inline void Dispose(); | 377 inline void Dispose(); |
| 378 | 378 |
| 379 /** | 379 /** |
| 380 * Make the reference to this object weak. When only weak handles | 380 * Make the reference to this object weak. When only weak handles |
| 381 * refer to the object, the garbage collector will perform a | 381 * refer to the object, the garbage collector will perform a |
| 382 * callback to the given V8::WeakReferenceCallback function, passing | 382 * callback to the given V8::WeakReferenceCallback function, passing |
| 383 * it the object reference and the given parameters. | 383 * it the object reference and the given parameters. |
| 384 */ | 384 */ |
| 385 inline void MakeWeak(void* parameters, WeakReferenceCallback callback); | 385 inline void MakeWeak(void* parameters, WeakReferenceCallback callback); |
| 386 | 386 |
| 387 /** Clears the weak reference to this object.*/ | 387 /** Clears the weak reference to this object.*/ |
| 388 inline void ClearWeak(); | 388 inline void ClearWeak(); |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * Marks the reference to this object independent. Garbage collector |
| 392 * is free to ignore any object groups containing this object. |
| 393 * Weak callback for an independent handle should not |
| 394 * assume that it will be preceded by a global GC prologue callback |
| 395 * or followed by a global GC epilogue callback. |
| 396 */ |
| 397 inline void MarkIndependent(); |
| 398 |
| 399 /** |
| 391 *Checks if the handle holds the only reference to an object. | 400 *Checks if the handle holds the only reference to an object. |
| 392 */ | 401 */ |
| 393 inline bool IsNearDeath() const; | 402 inline bool IsNearDeath() const; |
| 394 | 403 |
| 395 /** | 404 /** |
| 396 * Returns true if the handle's reference is weak. | 405 * Returns true if the handle's reference is weak. |
| 397 */ | 406 */ |
| 398 inline bool IsWeak() const; | 407 inline bool IsWeak() const; |
| 399 | 408 |
| 400 /** | 409 /** |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 * Returns the number of StackFrames. | 777 * Returns the number of StackFrames. |
| 769 */ | 778 */ |
| 770 int GetFrameCount() const; | 779 int GetFrameCount() const; |
| 771 | 780 |
| 772 /** | 781 /** |
| 773 * Returns StackTrace as a v8::Array that contains StackFrame objects. | 782 * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 774 */ | 783 */ |
| 775 Local<Array> AsArray(); | 784 Local<Array> AsArray(); |
| 776 | 785 |
| 777 /** | 786 /** |
| 778 * Grab a snapshot of the the current JavaScript execution stack. | 787 * Grab a snapshot of the current JavaScript execution stack. |
| 779 * | 788 * |
| 780 * \param frame_limit The maximum number of stack frames we want to capture. | 789 * \param frame_limit The maximum number of stack frames we want to capture. |
| 781 * \param options Enumerates the set of things we will capture for each | 790 * \param options Enumerates the set of things we will capture for each |
| 782 * StackFrame. | 791 * StackFrame. |
| 783 */ | 792 */ |
| 784 static Local<StackTrace> CurrentStackTrace( | 793 static Local<StackTrace> CurrentStackTrace( |
| 785 int frame_limit, | 794 int frame_limit, |
| 786 StackTraceOptions options = kOverview); | 795 StackTraceOptions options = kOverview); |
| 787 }; | 796 }; |
| 788 | 797 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 */ | 836 */ |
| 828 Local<String> GetFunctionName() const; | 837 Local<String> GetFunctionName() const; |
| 829 | 838 |
| 830 /** | 839 /** |
| 831 * Returns whether or not the associated function is compiled via a call to | 840 * Returns whether or not the associated function is compiled via a call to |
| 832 * eval(). | 841 * eval(). |
| 833 */ | 842 */ |
| 834 bool IsEval() const; | 843 bool IsEval() const; |
| 835 | 844 |
| 836 /** | 845 /** |
| 837 * Returns whther or not the associated function is called as a | 846 * Returns whether or not the associated function is called as a |
| 838 * constructor via "new". | 847 * constructor via "new". |
| 839 */ | 848 */ |
| 840 bool IsConstructor() const; | 849 bool IsConstructor() const; |
| 841 }; | 850 }; |
| 842 | 851 |
| 843 | 852 |
| 844 // --- Value --- | 853 // --- Value --- |
| 845 | 854 |
| 846 | 855 |
| 847 /** | 856 /** |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 * this function should not otherwise delete or modify the resource. Neither | 1184 * this function should not otherwise delete or modify the resource. Neither |
| 1176 * should the underlying buffer be deallocated or modified except through the | 1185 * should the underlying buffer be deallocated or modified except through the |
| 1177 * destructor of the external string resource. | 1186 * destructor of the external string resource. |
| 1178 */ | 1187 */ |
| 1179 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); | 1188 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); |
| 1180 | 1189 |
| 1181 /** | 1190 /** |
| 1182 * Associate an external string resource with this string by transforming it | 1191 * Associate an external string resource with this string by transforming it |
| 1183 * in place so that existing references to this string in the JavaScript heap | 1192 * in place so that existing references to this string in the JavaScript heap |
| 1184 * will use the external string resource. The external string resource's | 1193 * will use the external string resource. The external string resource's |
| 1185 * character contents needs to be equivalent to this string. | 1194 * character contents need to be equivalent to this string. |
| 1186 * Returns true if the string has been changed to be an external string. | 1195 * Returns true if the string has been changed to be an external string. |
| 1187 * The string is not modified if the operation fails. See NewExternal for | 1196 * The string is not modified if the operation fails. See NewExternal for |
| 1188 * information on the lifetime of the resource. | 1197 * information on the lifetime of the resource. |
| 1189 */ | 1198 */ |
| 1190 V8EXPORT bool MakeExternal(ExternalStringResource* resource); | 1199 V8EXPORT bool MakeExternal(ExternalStringResource* resource); |
| 1191 | 1200 |
| 1192 /** | 1201 /** |
| 1193 * Creates a new external string using the ascii data defined in the given | 1202 * Creates a new external string using the ascii data defined in the given |
| 1194 * resource. When the external string is no longer live on V8's heap the | 1203 * resource. When the external string is no longer live on V8's heap the |
| 1195 * resource will be disposed by calling its Dispose method. The caller of | 1204 * resource will be disposed by calling its Dispose method. The caller of |
| 1196 * this function should not otherwise delete or modify the resource. Neither | 1205 * this function should not otherwise delete or modify the resource. Neither |
| 1197 * should the underlying buffer be deallocated or modified except through the | 1206 * should the underlying buffer be deallocated or modified except through the |
| 1198 * destructor of the external string resource. | 1207 * destructor of the external string resource. |
| 1199 */ | 1208 */ |
| 1200 V8EXPORT static Local<String> NewExternal( | 1209 V8EXPORT static Local<String> NewExternal( |
| 1201 ExternalAsciiStringResource* resource); | 1210 ExternalAsciiStringResource* resource); |
| 1202 | 1211 |
| 1203 /** | 1212 /** |
| 1204 * Associate an external string resource with this string by transforming it | 1213 * Associate an external string resource with this string by transforming it |
| 1205 * in place so that existing references to this string in the JavaScript heap | 1214 * in place so that existing references to this string in the JavaScript heap |
| 1206 * will use the external string resource. The external string resource's | 1215 * will use the external string resource. The external string resource's |
| 1207 * character contents needs to be equivalent to this string. | 1216 * character contents need to be equivalent to this string. |
| 1208 * Returns true if the string has been changed to be an external string. | 1217 * Returns true if the string has been changed to be an external string. |
| 1209 * The string is not modified if the operation fails. See NewExternal for | 1218 * The string is not modified if the operation fails. See NewExternal for |
| 1210 * information on the lifetime of the resource. | 1219 * information on the lifetime of the resource. |
| 1211 */ | 1220 */ |
| 1212 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); | 1221 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); |
| 1213 | 1222 |
| 1214 /** | 1223 /** |
| 1215 * Returns true if this string can be made external. | 1224 * Returns true if this string can be made external. |
| 1216 */ | 1225 */ |
| 1217 V8EXPORT bool CanMakeExternal(); | 1226 V8EXPORT bool CanMakeExternal(); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1533 V8EXPORT bool HasIndexedLookupInterceptor(); | 1542 V8EXPORT bool HasIndexedLookupInterceptor(); |
| 1534 | 1543 |
| 1535 /** | 1544 /** |
| 1536 * Turns on access check on the object if the object is an instance of | 1545 * Turns on access check on the object if the object is an instance of |
| 1537 * a template that has access check callbacks. If an object has no | 1546 * a template that has access check callbacks. If an object has no |
| 1538 * access check info, the object cannot be accessed by anyone. | 1547 * access check info, the object cannot be accessed by anyone. |
| 1539 */ | 1548 */ |
| 1540 V8EXPORT void TurnOnAccessCheck(); | 1549 V8EXPORT void TurnOnAccessCheck(); |
| 1541 | 1550 |
| 1542 /** | 1551 /** |
| 1543 * Returns the identity hash for this object. The current implemenation uses | 1552 * Returns the identity hash for this object. The current implementation |
| 1544 * a hidden property on the object to store the identity hash. | 1553 * uses a hidden property on the object to store the identity hash. |
| 1545 * | 1554 * |
| 1546 * The return value will never be 0. Also, it is not guaranteed to be | 1555 * The return value will never be 0. Also, it is not guaranteed to be |
| 1547 * unique. | 1556 * unique. |
| 1548 */ | 1557 */ |
| 1549 V8EXPORT int GetIdentityHash(); | 1558 V8EXPORT int GetIdentityHash(); |
| 1550 | 1559 |
| 1551 /** | 1560 /** |
| 1552 * Access hidden properties on JavaScript objects. These properties are | 1561 * Access hidden properties on JavaScript objects. These properties are |
| 1553 * hidden from the executing JavaScript and only accessible through the V8 | 1562 * hidden from the executing JavaScript and only accessible through the V8 |
| 1554 * C++ API. Hidden properties introduced by V8 internally (for example the | 1563 * C++ API. Hidden properties introduced by V8 internally (for example the |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 V8EXPORT void SetIndexedPropertiesToExternalArrayData( | 1609 V8EXPORT void SetIndexedPropertiesToExternalArrayData( |
| 1601 void* data, | 1610 void* data, |
| 1602 ExternalArrayType array_type, | 1611 ExternalArrayType array_type, |
| 1603 int number_of_elements); | 1612 int number_of_elements); |
| 1604 V8EXPORT bool HasIndexedPropertiesInExternalArrayData(); | 1613 V8EXPORT bool HasIndexedPropertiesInExternalArrayData(); |
| 1605 V8EXPORT void* GetIndexedPropertiesExternalArrayData(); | 1614 V8EXPORT void* GetIndexedPropertiesExternalArrayData(); |
| 1606 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); | 1615 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 1607 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength(); | 1616 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength(); |
| 1608 | 1617 |
| 1609 /** | 1618 /** |
| 1619 * Checks whether a callback is set by the |
| 1620 * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1621 * When an Object is callable this method returns true. |
| 1622 */ |
| 1623 V8EXPORT bool IsCallable(); |
| 1624 |
| 1625 /** |
| 1610 * Call an Object as a function if a callback is set by the | 1626 * Call an Object as a function if a callback is set by the |
| 1611 * ObjectTemplate::SetCallAsFunctionHandler method. | 1627 * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1612 */ | 1628 */ |
| 1613 V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv, | 1629 V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv, |
| 1614 int argc, | 1630 int argc, |
| 1615 Handle<Value> argv[]); | 1631 Handle<Value> argv[]); |
| 1616 | 1632 |
| 1633 /** |
| 1634 * Call an Object as a constructor if a callback is set by the |
| 1635 * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1636 * Note: This method behaves like the Function::NewInstance method. |
| 1637 */ |
| 1638 V8EXPORT Local<Value> CallAsConstructor(int argc, |
| 1639 Handle<Value> argv[]); |
| 1640 |
| 1617 V8EXPORT static Local<Object> New(); | 1641 V8EXPORT static Local<Object> New(); |
| 1618 static inline Object* Cast(Value* obj); | 1642 static inline Object* Cast(Value* obj); |
| 1619 private: | 1643 private: |
| 1620 V8EXPORT Object(); | 1644 V8EXPORT Object(); |
| 1621 V8EXPORT static void CheckCast(Value* obj); | 1645 V8EXPORT static void CheckCast(Value* obj); |
| 1622 V8EXPORT Local<Value> CheckedGetInternalField(int index); | 1646 V8EXPORT Local<Value> CheckedGetInternalField(int index); |
| 1623 V8EXPORT void* SlowGetPointerFromInternalField(int index); | 1647 V8EXPORT void* SlowGetPointerFromInternalField(int index); |
| 1624 | 1648 |
| 1625 /** | 1649 /** |
| 1626 * If quick access to the internal field is possible this method | 1650 * If quick access to the internal field is possible this method |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2221 | 2245 |
| 2222 /** | 2246 /** |
| 2223 * Sets an indexed property handler on the object template. | 2247 * Sets an indexed property handler on the object template. |
| 2224 * | 2248 * |
| 2225 * Whenever an indexed property is accessed on objects created from | 2249 * Whenever an indexed property is accessed on objects created from |
| 2226 * this object template, the provided callback is invoked instead of | 2250 * this object template, the provided callback is invoked instead of |
| 2227 * accessing the property directly on the JavaScript object. | 2251 * accessing the property directly on the JavaScript object. |
| 2228 * | 2252 * |
| 2229 * \param getter The callback to invoke when getting a property. | 2253 * \param getter The callback to invoke when getting a property. |
| 2230 * \param setter The callback to invoke when setting a property. | 2254 * \param setter The callback to invoke when setting a property. |
| 2231 * \param query The callback to invoke to check is an object has a property. | 2255 * \param query The callback to invoke to check if an object has a property. |
| 2232 * \param deleter The callback to invoke when deleting a property. | 2256 * \param deleter The callback to invoke when deleting a property. |
| 2233 * \param enumerator The callback to invoke to enumerate all the indexed | 2257 * \param enumerator The callback to invoke to enumerate all the indexed |
| 2234 * properties of an object. | 2258 * properties of an object. |
| 2235 * \param data A piece of data that will be passed to the callbacks | 2259 * \param data A piece of data that will be passed to the callbacks |
| 2236 * whenever they are invoked. | 2260 * whenever they are invoked. |
| 2237 */ | 2261 */ |
| 2238 void SetIndexedPropertyHandler(IndexedPropertyGetter getter, | 2262 void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 2239 IndexedPropertySetter setter = 0, | 2263 IndexedPropertySetter setter = 0, |
| 2240 IndexedPropertyQuery query = 0, | 2264 IndexedPropertyQuery query = 0, |
| 2241 IndexedPropertyDeleter deleter = 0, | 2265 IndexedPropertyDeleter deleter = 0, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2639 * Requires: this == Isolate::GetCurrent(). | 2663 * Requires: this == Isolate::GetCurrent(). |
| 2640 */ | 2664 */ |
| 2641 void Exit(); | 2665 void Exit(); |
| 2642 | 2666 |
| 2643 /** | 2667 /** |
| 2644 * Disposes the isolate. The isolate must not be entered by any | 2668 * Disposes the isolate. The isolate must not be entered by any |
| 2645 * thread to be disposable. | 2669 * thread to be disposable. |
| 2646 */ | 2670 */ |
| 2647 void Dispose(); | 2671 void Dispose(); |
| 2648 | 2672 |
| 2673 /** |
| 2674 * Associate embedder-specific data with the isolate |
| 2675 */ |
| 2676 void SetData(void* data); |
| 2677 |
| 2678 /** |
| 2679 * Retrive embedder-specific data from the isolate. |
| 2680 * Returns NULL if SetData has never been called. |
| 2681 */ |
| 2682 void* GetData(); |
| 2683 |
| 2649 private: | 2684 private: |
| 2650 | 2685 |
| 2651 Isolate(); | 2686 Isolate(); |
| 2652 Isolate(const Isolate&); | 2687 Isolate(const Isolate&); |
| 2653 ~Isolate(); | 2688 ~Isolate(); |
| 2654 Isolate& operator=(const Isolate&); | 2689 Isolate& operator=(const Isolate&); |
| 2655 void* operator new(size_t size); | 2690 void* operator new(size_t size); |
| 2656 void operator delete(void*, size_t); | 2691 void operator delete(void*, size_t); |
| 2657 }; | 2692 }; |
| 2658 | 2693 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2684 static void SetAllowCodeGenerationFromStringsCallback( | 2719 static void SetAllowCodeGenerationFromStringsCallback( |
| 2685 AllowCodeGenerationFromStringsCallback that); | 2720 AllowCodeGenerationFromStringsCallback that); |
| 2686 | 2721 |
| 2687 /** | 2722 /** |
| 2688 * Ignore out-of-memory exceptions. | 2723 * Ignore out-of-memory exceptions. |
| 2689 * | 2724 * |
| 2690 * V8 running out of memory is treated as a fatal error by default. | 2725 * V8 running out of memory is treated as a fatal error by default. |
| 2691 * This means that the fatal error handler is called and that V8 is | 2726 * This means that the fatal error handler is called and that V8 is |
| 2692 * terminated. | 2727 * terminated. |
| 2693 * | 2728 * |
| 2694 * IgnoreOutOfMemoryException can be used to not treat a | 2729 * IgnoreOutOfMemoryException can be used to not treat an |
| 2695 * out-of-memory situation as a fatal error. This way, the contexts | 2730 * out-of-memory situation as a fatal error. This way, the contexts |
| 2696 * that did not cause the out of memory problem might be able to | 2731 * that did not cause the out of memory problem might be able to |
| 2697 * continue execution. | 2732 * continue execution. |
| 2698 */ | 2733 */ |
| 2699 static void IgnoreOutOfMemoryException(); | 2734 static void IgnoreOutOfMemoryException(); |
| 2700 | 2735 |
| 2701 /** | 2736 /** |
| 2702 * Check if V8 is dead and therefore unusable. This is the case after | 2737 * Check if V8 is dead and therefore unusable. This is the case after |
| 2703 * fatal errors such as out-of-memory situations. | 2738 * fatal errors such as out-of-memory situations. |
| 2704 */ | 2739 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2720 * ... make sure the decompressed data stays valid until V8 shutdown | 2755 * ... make sure the decompressed data stays valid until V8 shutdown |
| 2721 */ | 2756 */ |
| 2722 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); | 2757 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 2723 static int GetCompressedStartupDataCount(); | 2758 static int GetCompressedStartupDataCount(); |
| 2724 static void GetCompressedStartupData(StartupData* compressed_data); | 2759 static void GetCompressedStartupData(StartupData* compressed_data); |
| 2725 static void SetDecompressedStartupData(StartupData* decompressed_data); | 2760 static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 2726 | 2761 |
| 2727 /** | 2762 /** |
| 2728 * Adds a message listener. | 2763 * Adds a message listener. |
| 2729 * | 2764 * |
| 2730 * The same message listener can be added more than once and it that | 2765 * The same message listener can be added more than once and in that |
| 2731 * case it will be called more than once for each message. | 2766 * case it will be called more than once for each message. |
| 2732 */ | 2767 */ |
| 2733 static bool AddMessageListener(MessageCallback that, | 2768 static bool AddMessageListener(MessageCallback that, |
| 2734 Handle<Value> data = Handle<Value>()); | 2769 Handle<Value> data = Handle<Value>()); |
| 2735 | 2770 |
| 2736 /** | 2771 /** |
| 2737 * Remove all message listeners from the specified callback function. | 2772 * Remove all message listeners from the specified callback function. |
| 2738 */ | 2773 */ |
| 2739 static void RemoveMessageListeners(MessageCallback that); | 2774 static void RemoveMessageListeners(MessageCallback that); |
| 2740 | 2775 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3000 * | 3035 * |
| 3001 * TerminateExecution should only be called when then V8 lock has | 3036 * TerminateExecution should only be called when then V8 lock has |
| 3002 * been acquired with a Locker object. Therefore, in order to be | 3037 * been acquired with a Locker object. Therefore, in order to be |
| 3003 * able to terminate long-running threads, preemption must be | 3038 * able to terminate long-running threads, preemption must be |
| 3004 * enabled to allow the user of TerminateExecution to acquire the | 3039 * enabled to allow the user of TerminateExecution to acquire the |
| 3005 * lock. | 3040 * lock. |
| 3006 * | 3041 * |
| 3007 * The termination is achieved by throwing an exception that is | 3042 * The termination is achieved by throwing an exception that is |
| 3008 * uncatchable by JavaScript exception handlers. Termination | 3043 * uncatchable by JavaScript exception handlers. Termination |
| 3009 * exceptions act as if they were caught by a C++ TryCatch exception | 3044 * exceptions act as if they were caught by a C++ TryCatch exception |
| 3010 * handlers. If forceful termination is used, any C++ TryCatch | 3045 * handler. If forceful termination is used, any C++ TryCatch |
| 3011 * exception handler that catches an exception should check if that | 3046 * exception handler that catches an exception should check if that |
| 3012 * exception is a termination exception and immediately return if | 3047 * exception is a termination exception and immediately return if |
| 3013 * that is the case. Returning immediately in that case will | 3048 * that is the case. Returning immediately in that case will |
| 3014 * continue the propagation of the termination exception if needed. | 3049 * continue the propagation of the termination exception if needed. |
| 3015 * | 3050 * |
| 3016 * The thread id passed to TerminateExecution must have been | 3051 * The thread id passed to TerminateExecution must have been |
| 3017 * obtained by calling GetCurrentThreadId on the thread in question. | 3052 * obtained by calling GetCurrentThreadId on the thread in question. |
| 3018 * | 3053 * |
| 3019 * \param thread_id The thread id of the thread to terminate. | 3054 * \param thread_id The thread id of the thread to terminate. |
| 3020 */ | 3055 */ |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3084 | 3119 |
| 3085 private: | 3120 private: |
| 3086 V8(); | 3121 V8(); |
| 3087 | 3122 |
| 3088 static internal::Object** GlobalizeReference(internal::Object** handle); | 3123 static internal::Object** GlobalizeReference(internal::Object** handle); |
| 3089 static void DisposeGlobal(internal::Object** global_handle); | 3124 static void DisposeGlobal(internal::Object** global_handle); |
| 3090 static void MakeWeak(internal::Object** global_handle, | 3125 static void MakeWeak(internal::Object** global_handle, |
| 3091 void* data, | 3126 void* data, |
| 3092 WeakReferenceCallback); | 3127 WeakReferenceCallback); |
| 3093 static void ClearWeak(internal::Object** global_handle); | 3128 static void ClearWeak(internal::Object** global_handle); |
| 3129 static void MarkIndependent(internal::Object** global_handle); |
| 3094 static bool IsGlobalNearDeath(internal::Object** global_handle); | 3130 static bool IsGlobalNearDeath(internal::Object** global_handle); |
| 3095 static bool IsGlobalWeak(internal::Object** global_handle); | 3131 static bool IsGlobalWeak(internal::Object** global_handle); |
| 3096 static void SetWrapperClassId(internal::Object** global_handle, | 3132 static void SetWrapperClassId(internal::Object** global_handle, |
| 3097 uint16_t class_id); | 3133 uint16_t class_id); |
| 3098 | 3134 |
| 3099 template <class T> friend class Handle; | 3135 template <class T> friend class Handle; |
| 3100 template <class T> friend class Local; | 3136 template <class T> friend class Local; |
| 3101 template <class T> friend class Persistent; | 3137 template <class T> friend class Persistent; |
| 3102 friend class Context; | 3138 friend class Context; |
| 3103 }; | 3139 }; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3386 | 3422 |
| 3387 /** | 3423 /** |
| 3388 * Multiple threads in V8 are allowed, but only one thread at a time | 3424 * Multiple threads in V8 are allowed, but only one thread at a time |
| 3389 * is allowed to use any given V8 isolate. See Isolate class | 3425 * is allowed to use any given V8 isolate. See Isolate class |
| 3390 * comments. The definition of 'using V8 isolate' includes | 3426 * comments. The definition of 'using V8 isolate' includes |
| 3391 * accessing handles or holding onto object pointers obtained | 3427 * accessing handles or holding onto object pointers obtained |
| 3392 * from V8 handles while in the particular V8 isolate. It is up | 3428 * from V8 handles while in the particular V8 isolate. It is up |
| 3393 * to the user of V8 to ensure (perhaps with locking) that this | 3429 * to the user of V8 to ensure (perhaps with locking) that this |
| 3394 * constraint is not violated. | 3430 * constraint is not violated. |
| 3395 * | 3431 * |
| 3396 * More then one thread and multiple V8 isolates can be used | 3432 * v8::Locker is a scoped lock object. While it's |
| 3397 * without any locking if each isolate is created and accessed | 3433 * active (i.e. between its construction and destruction) the current thread is |
| 3398 * by a single thread only. For example, one thread can use | 3434 * allowed to use the locked isolate. V8 guarantees that an isolate can be locke
d |
| 3399 * multiple isolates or multiple threads can each create and run | 3435 * by at most one thread at any time. In other words, the scope of a v8::Locker
is |
| 3400 * their own isolate. | 3436 * a critical section. |
| 3401 * | 3437 * |
| 3402 * If you wish to start using V8 isolate in more then one thread | 3438 * Sample usage: |
| 3403 * you can do this by constructing a v8::Locker object to guard | 3439 * \code |
| 3404 * access to the isolate. After the code using V8 has completed | |
| 3405 * for the current thread you can call the destructor. This can | |
| 3406 * be combined with C++ scope-based construction as follows | |
| 3407 * (assumes the default isolate that is used if not specified as | |
| 3408 * a parameter for the Locker): | |
| 3409 * | |
| 3410 * \code | |
| 3411 * ... | 3440 * ... |
| 3412 * { | 3441 * { |
| 3413 * v8::Locker locker; | 3442 * v8::Locker locker(isolate); |
| 3443 * v8::Isolate::Scope isolate_scope(isolate); |
| 3414 * ... | 3444 * ... |
| 3415 * // Code using V8 goes here. | 3445 * // Code using V8 and isolate goes here. |
| 3416 * ... | 3446 * ... |
| 3417 * } // Destructor called here | 3447 * } // Destructor called here |
| 3418 * \endcode | 3448 * \endcode |
| 3419 * | 3449 * |
| 3420 * If you wish to stop using V8 in a thread A you can do this by either | 3450 * If you wish to stop using V8 in a thread A you can do this either |
| 3421 * by destroying the v8::Locker object as above or by constructing a | 3451 * by destroying the v8::Locker object as above or by constructing a |
| 3422 * v8::Unlocker object: | 3452 * v8::Unlocker object: |
| 3423 * | 3453 * |
| 3424 * \code | 3454 * \code |
| 3425 * { | 3455 * { |
| 3426 * v8::Unlocker unlocker; | 3456 * isolate->Exit(); |
| 3457 * v8::Unlocker unlocker(isolate); |
| 3427 * ... | 3458 * ... |
| 3428 * // Code not using V8 goes here while V8 can run in another thread. | 3459 * // Code not using V8 goes here while V8 can run in another thread. |
| 3429 * ... | 3460 * ... |
| 3430 * } // Destructor called here. | 3461 * } // Destructor called here. |
| 3462 * isolate->Enter(); |
| 3431 * \endcode | 3463 * \endcode |
| 3432 * | 3464 * |
| 3433 * The Unlocker object is intended for use in a long-running callback | 3465 * The Unlocker object is intended for use in a long-running callback |
| 3434 * from V8, where you want to release the V8 lock for other threads to | 3466 * from V8, where you want to release the V8 lock for other threads to |
| 3435 * use. | 3467 * use. |
| 3436 * | 3468 * |
| 3437 * The v8::Locker is a recursive lock. That is, you can lock more than | 3469 * The v8::Locker is a recursive lock. That is, you can lock more than |
| 3438 * once in a given thread. This can be useful if you have code that can | 3470 * once in a given thread. This can be useful if you have code that can |
| 3439 * be called either from code that holds the lock or from code that does | 3471 * be called either from code that holds the lock or from code that does |
| 3440 * not. The Unlocker is not recursive so you can not have several | 3472 * not. The Unlocker is not recursive so you can not have several |
| 3441 * Unlockers on the stack at once, and you can not use an Unlocker in a | 3473 * Unlockers on the stack at once, and you can not use an Unlocker in a |
| 3442 * thread that is not inside a Locker's scope. | 3474 * thread that is not inside a Locker's scope. |
| 3443 * | 3475 * |
| 3444 * An unlocker will unlock several lockers if it has to and reinstate | 3476 * An unlocker will unlock several lockers if it has to and reinstate |
| 3445 * the correct depth of locking on its destruction. eg.: | 3477 * the correct depth of locking on its destruction. eg.: |
| 3446 * | 3478 * |
| 3447 * \code | 3479 * \code |
| 3448 * // V8 not locked. | 3480 * // V8 not locked. |
| 3449 * { | 3481 * { |
| 3450 * v8::Locker locker; | 3482 * v8::Locker locker(isolate); |
| 3483 * Isolate::Scope isolate_scope(isolate); |
| 3451 * // V8 locked. | 3484 * // V8 locked. |
| 3452 * { | 3485 * { |
| 3453 * v8::Locker another_locker; | 3486 * v8::Locker another_locker(isolate); |
| 3454 * // V8 still locked (2 levels). | 3487 * // V8 still locked (2 levels). |
| 3455 * { | 3488 * { |
| 3456 * v8::Unlocker unlocker; | 3489 * isolate->Exit(); |
| 3490 * v8::Unlocker unlocker(isolate); |
| 3457 * // V8 not locked. | 3491 * // V8 not locked. |
| 3458 * } | 3492 * } |
| 3493 * isolate->Enter(); |
| 3459 * // V8 locked again (2 levels). | 3494 * // V8 locked again (2 levels). |
| 3460 * } | 3495 * } |
| 3461 * // V8 still locked (1 level). | 3496 * // V8 still locked (1 level). |
| 3462 * } | 3497 * } |
| 3463 * // V8 Now no longer locked. | 3498 * // V8 Now no longer locked. |
| 3464 * \endcode | 3499 * \endcode |
| 3500 * |
| 3501 * |
| 3465 */ | 3502 */ |
| 3466 class V8EXPORT Unlocker { | 3503 class V8EXPORT Unlocker { |
| 3467 public: | 3504 public: |
| 3468 Unlocker(); | 3505 /** |
| 3506 * Initialize Unlocker for a given Isolate. NULL means default isolate. |
| 3507 */ |
| 3508 explicit Unlocker(Isolate* isolate = NULL); |
| 3469 ~Unlocker(); | 3509 ~Unlocker(); |
| 3510 private: |
| 3511 internal::Isolate* isolate_; |
| 3470 }; | 3512 }; |
| 3471 | 3513 |
| 3472 | 3514 |
| 3473 class V8EXPORT Locker { | 3515 class V8EXPORT Locker { |
| 3474 public: | 3516 public: |
| 3475 Locker(); | 3517 /** |
| 3518 * Initialize Locker for a given Isolate. NULL means default isolate. |
| 3519 */ |
| 3520 explicit Locker(Isolate* isolate = NULL); |
| 3476 ~Locker(); | 3521 ~Locker(); |
| 3477 | 3522 |
| 3478 /** | 3523 /** |
| 3479 * Start preemption. | 3524 * Start preemption. |
| 3480 * | 3525 * |
| 3481 * When preemption is started, a timer is fired every n milli seconds | 3526 * When preemption is started, a timer is fired every n milliseconds |
| 3482 * that will switch between multiple threads that are in contention | 3527 * that will switch between multiple threads that are in contention |
| 3483 * for the V8 lock. | 3528 * for the V8 lock. |
| 3484 */ | 3529 */ |
| 3485 static void StartPreemption(int every_n_ms); | 3530 static void StartPreemption(int every_n_ms); |
| 3486 | 3531 |
| 3487 /** | 3532 /** |
| 3488 * Stop preemption. | 3533 * Stop preemption. |
| 3489 */ | 3534 */ |
| 3490 static void StopPreemption(); | 3535 static void StopPreemption(); |
| 3491 | 3536 |
| 3492 /** | 3537 /** |
| 3493 * Returns whether or not the locker is locked by the current thread. | 3538 * Returns whether or not the locker for a given isolate, or default isolate i
f NULL is given, |
| 3539 * is locked by the current thread. |
| 3494 */ | 3540 */ |
| 3495 static bool IsLocked(); | 3541 static bool IsLocked(Isolate* isolate = NULL); |
| 3496 | 3542 |
| 3497 /** | 3543 /** |
| 3498 * Returns whether v8::Locker is being used by this V8 instance. | 3544 * Returns whether v8::Locker is being used by this V8 instance. |
| 3499 */ | 3545 */ |
| 3500 static bool IsActive() { return active_; } | 3546 static bool IsActive() { return active_; } |
| 3501 | 3547 |
| 3502 private: | 3548 private: |
| 3503 bool has_lock_; | 3549 bool has_lock_; |
| 3504 bool top_level_; | 3550 bool top_level_; |
| 3551 internal::Isolate* isolate_; |
| 3505 | 3552 |
| 3506 static bool active_; | 3553 static bool active_; |
| 3507 | 3554 |
| 3508 // Disallow copying and assigning. | 3555 // Disallow copying and assigning. |
| 3509 Locker(const Locker&); | 3556 Locker(const Locker&); |
| 3510 void operator=(const Locker&); | 3557 void operator=(const Locker&); |
| 3511 }; | 3558 }; |
| 3512 | 3559 |
| 3513 | 3560 |
| 3514 /** | 3561 /** |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3649 static const int kHeapObjectMapOffset = 0; | 3696 static const int kHeapObjectMapOffset = 0; |
| 3650 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 3697 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
| 3651 static const int kStringResourceOffset = | 3698 static const int kStringResourceOffset = |
| 3652 InternalConstants<kApiPointerSize>::kStringResourceOffset; | 3699 InternalConstants<kApiPointerSize>::kStringResourceOffset; |
| 3653 | 3700 |
| 3654 static const int kProxyProxyOffset = kApiPointerSize; | 3701 static const int kProxyProxyOffset = kApiPointerSize; |
| 3655 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 3702 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
| 3656 static const int kFullStringRepresentationMask = 0x07; | 3703 static const int kFullStringRepresentationMask = 0x07; |
| 3657 static const int kExternalTwoByteRepresentationTag = 0x02; | 3704 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 3658 | 3705 |
| 3659 static const int kJSObjectType = 0xa2; | 3706 static const int kJSObjectType = 0xa3; |
| 3660 static const int kFirstNonstringType = 0x80; | 3707 static const int kFirstNonstringType = 0x80; |
| 3661 static const int kProxyType = 0x85; | 3708 static const int kProxyType = 0x85; |
| 3662 | 3709 |
| 3663 static inline bool HasHeapObjectTag(internal::Object* value) { | 3710 static inline bool HasHeapObjectTag(internal::Object* value) { |
| 3664 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 3711 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 3665 kHeapObjectTag); | 3712 kHeapObjectTag); |
| 3666 } | 3713 } |
| 3667 | 3714 |
| 3668 static inline bool HasSmiTag(internal::Object* value) { | 3715 static inline bool HasSmiTag(internal::Object* value) { |
| 3669 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 3716 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3776 parameters, | 3823 parameters, |
| 3777 callback); | 3824 callback); |
| 3778 } | 3825 } |
| 3779 | 3826 |
| 3780 template <class T> | 3827 template <class T> |
| 3781 void Persistent<T>::ClearWeak() { | 3828 void Persistent<T>::ClearWeak() { |
| 3782 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); | 3829 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); |
| 3783 } | 3830 } |
| 3784 | 3831 |
| 3785 template <class T> | 3832 template <class T> |
| 3833 void Persistent<T>::MarkIndependent() { |
| 3834 V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this)); |
| 3835 } |
| 3836 |
| 3837 template <class T> |
| 3786 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | 3838 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
| 3787 V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id); | 3839 V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id); |
| 3788 } | 3840 } |
| 3789 | 3841 |
| 3790 Arguments::Arguments(internal::Object** implicit_args, | 3842 Arguments::Arguments(internal::Object** implicit_args, |
| 3791 internal::Object** values, int length, | 3843 internal::Object** values, int length, |
| 3792 bool is_construct_call) | 3844 bool is_construct_call) |
| 3793 : implicit_args_(implicit_args), | 3845 : implicit_args_(implicit_args), |
| 3794 values_(values), | 3846 values_(values), |
| 3795 length_(length), | 3847 length_(length), |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4063 | 4115 |
| 4064 | 4116 |
| 4065 } // namespace v8 | 4117 } // namespace v8 |
| 4066 | 4118 |
| 4067 | 4119 |
| 4068 #undef V8EXPORT | 4120 #undef V8EXPORT |
| 4069 #undef TYPE_CHECK | 4121 #undef TYPE_CHECK |
| 4070 | 4122 |
| 4071 | 4123 |
| 4072 #endif // V8_H_ | 4124 #endif // V8_H_ |
| OLD | NEW |