Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: include/v8.h

Issue 12494012: new style of property/function callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/x64/macro-assembler-x64.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 class String; 128 class String;
129 class StringObject; 129 class StringObject;
130 class Symbol; 130 class Symbol;
131 class SymbolObject; 131 class SymbolObject;
132 class Uint32; 132 class Uint32;
133 class Utils; 133 class Utils;
134 class Value; 134 class Value;
135 template <class T> class Handle; 135 template <class T> class Handle;
136 template <class T> class Local; 136 template <class T> class Local;
137 template <class T> class Persistent; 137 template <class T> class Persistent;
138 class FunctionTemplate;
139 class ObjectTemplate;
140 class Data;
141 class AccessorInfo;
142 template<typename T> class PropertyCallbackInfo;
143 class StackTrace;
144 class StackFrame;
145 class Isolate;
146 class DeclaredAccessorDescriptor;
147 class ObjectOperationDescriptor;
148 class RawOperationDescriptor;
138 149
139 namespace internal { 150 namespace internal {
140 class Arguments; 151 class Arguments;
141 class Heap; 152 class Heap;
142 class HeapObject; 153 class HeapObject;
143 class Isolate; 154 class Isolate;
144 class Object; 155 class Object;
156 template<typename T>
157 class CustomArguments;
158 class PropertyCallbackArguments;
159 class FunctionCallbackArguments;
145 } 160 }
146 161
147 162
148 // --- Weak Handles --- 163 // --- Weak Handles ---
149 164
150 165
151 /** 166 /**
152 * A weak reference callback function. 167 * A weak reference callback function.
153 * 168 *
154 * This callback should either explicitly invoke Dispose on |object| if 169 * This callback should either explicitly invoke Dispose on |object| if
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 kExternalPixelArray 1626 kExternalPixelArray
1612 }; 1627 };
1613 1628
1614 /** 1629 /**
1615 * Accessor[Getter|Setter] are used as callback functions when 1630 * Accessor[Getter|Setter] are used as callback functions when
1616 * setting|getting a particular property. See Object and ObjectTemplate's 1631 * setting|getting a particular property. See Object and ObjectTemplate's
1617 * method SetAccessor. 1632 * method SetAccessor.
1618 */ 1633 */
1619 typedef Handle<Value> (*AccessorGetter)(Local<String> property, 1634 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
1620 const AccessorInfo& info); 1635 const AccessorInfo& info);
1636 typedef void (*AccessorGetterCallback)(
1637 Local<String> property,
1638 const PropertyCallbackInfo<Value>& info);
1621 1639
1622 1640
1623 typedef void (*AccessorSetter)(Local<String> property, 1641 typedef void (*AccessorSetter)(Local<String> property,
1624 Local<Value> value, 1642 Local<Value> value,
1625 const AccessorInfo& info); 1643 const AccessorInfo& info);
1644 typedef void (*AccessorSetterCallback)(
1645 Local<String> property,
1646 Local<Value> value,
1647 const PropertyCallbackInfo<void>& info);
1626 1648
1627 1649
1628 /** 1650 /**
1629 * Access control specifications. 1651 * Access control specifications.
1630 * 1652 *
1631 * Some accessors should be accessible across contexts. These 1653 * Some accessors should be accessible across contexts. These
1632 * accessors have an explicit access control parameter which specifies 1654 * accessors have an explicit access control parameter which specifies
1633 * the kind of cross-context access that should be allowed. 1655 * the kind of cross-context access that should be allowed.
1634 * 1656 *
1635 * Additionally, for security, accessors can prohibit overwriting by 1657 * Additionally, for security, accessors can prohibit overwriting by
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 bool Delete(Handle<Value> key); 1707 bool Delete(Handle<Value> key);
1686 1708
1687 // Delete a property on this object bypassing interceptors and 1709 // Delete a property on this object bypassing interceptors and
1688 // ignoring dont-delete attributes. 1710 // ignoring dont-delete attributes.
1689 bool ForceDelete(Handle<Value> key); 1711 bool ForceDelete(Handle<Value> key);
1690 1712
1691 bool Has(uint32_t index); 1713 bool Has(uint32_t index);
1692 1714
1693 bool Delete(uint32_t index); 1715 bool Delete(uint32_t index);
1694 1716
1717 // TODO(dcarney): deprecate
1695 bool SetAccessor(Handle<String> name, 1718 bool SetAccessor(Handle<String> name,
1696 AccessorGetter getter, 1719 AccessorGetter getter,
1697 AccessorSetter setter = 0, 1720 AccessorSetter setter = 0,
1698 Handle<Value> data = Handle<Value>(), 1721 Handle<Value> data = Handle<Value>(),
1699 AccessControl settings = DEFAULT, 1722 AccessControl settings = DEFAULT,
1700 PropertyAttribute attribute = None); 1723 PropertyAttribute attribute = None);
1724 bool SetAccessor(Handle<String> name,
1725 AccessorGetterCallback getter,
1726 AccessorSetterCallback setter = 0,
1727 Handle<Value> data = Handle<Value>(),
1728 AccessControl settings = DEFAULT,
1729 PropertyAttribute attribute = None);
1701 1730
1702 // This function is not yet stable and should not be used at this time. 1731 // This function is not yet stable and should not be used at this time.
1703 bool SetAccessor(Handle<String> name, 1732 bool SetAccessor(Handle<String> name,
1704 Handle<DeclaredAccessorDescriptor> descriptor, 1733 Handle<DeclaredAccessorDescriptor> descriptor,
1705 AccessControl settings = DEFAULT, 1734 AccessControl settings = DEFAULT,
1706 PropertyAttribute attribute = None); 1735 PropertyAttribute attribute = None);
1707 1736
1708 /** 1737 /**
1709 * Returns an array containing the names of the enumerable properties 1738 * Returns an array containing the names of the enumerable properties
1710 * of this object, including properties from prototype objects. The 1739 * of this object, including properties from prototype objects. The
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 PropertyAttribute attributes = None); 2192 PropertyAttribute attributes = None);
2164 V8_INLINE(void Set(const char* name, Handle<Data> value)); 2193 V8_INLINE(void Set(const char* name, Handle<Data> value));
2165 private: 2194 private:
2166 Template(); 2195 Template();
2167 2196
2168 friend class ObjectTemplate; 2197 friend class ObjectTemplate;
2169 friend class FunctionTemplate; 2198 friend class FunctionTemplate;
2170 }; 2199 };
2171 2200
2172 2201
2202 template<typename T>
2203 class V8EXPORT ReturnValue {
2204 public:
2205 V8_INLINE(explicit ReturnValue(internal::Object** slot));
2206 // Handle setters
2207 V8_INLINE(void Set(Persistent<T> handle));
2208 V8_INLINE(void Set(Handle<T> handle));
2209 // TODO(dcarney): implement
2210 // Fast primitive setters
2211 V8_INLINE(void Set(Isolate* isolate, bool));
2212 V8_INLINE(void Set(Isolate* isolate, float i));
2213 V8_INLINE(void Set(Isolate* isolate, double i));
2214 V8_INLINE(void Set(Isolate* isolate, int32_t i));
2215 V8_INLINE(void Set(Isolate* isolate, uint32_t i));
2216 // Fast JS primitive setters
2217 V8_INLINE(void SetNull(Isolate* isolate));
2218 V8_INLINE(void SetUndefined(Isolate* isolate));
2219 private:
2220 internal::Object** value_;
2221 };
2222
2223
2173 /** 2224 /**
2174 * The argument information given to function call callbacks. This 2225 * The argument information given to function call callbacks. This
2175 * class provides access to information about the context of the call, 2226 * class provides access to information about the context of the call,
2176 * including the receiver, the number and values of arguments, and 2227 * including the receiver, the number and values of arguments, and
2177 * the holder of the function. 2228 * the holder of the function.
2178 */ 2229 */
2179 class V8EXPORT Arguments { 2230 template<typename T>
2231 class V8EXPORT FunctionCallbackInfo {
2180 public: 2232 public:
2181 V8_INLINE(int Length() const); 2233 V8_INLINE(int Length() const);
2182 V8_INLINE(Local<Value> operator[](int i) const); 2234 V8_INLINE(Local<Value> operator[](int i) const);
2183 V8_INLINE(Local<Function> Callee() const); 2235 V8_INLINE(Local<Function> Callee() const);
2184 V8_INLINE(Local<Object> This() const); 2236 V8_INLINE(Local<Object> This() const);
2185 V8_INLINE(Local<Object> Holder() const); 2237 V8_INLINE(Local<Object> Holder() const);
2186 V8_INLINE(bool IsConstructCall() const); 2238 V8_INLINE(bool IsConstructCall() const);
2187 V8_INLINE(Local<Value> Data() const); 2239 V8_INLINE(Local<Value> Data() const);
2188 V8_INLINE(Isolate* GetIsolate() const); 2240 V8_INLINE(Isolate* GetIsolate() const);
2241 V8_INLINE(ReturnValue<T> GetReturnValue() const);
2189 2242
2190 private: 2243 protected:
2191 static const int kIsolateIndex = 0; 2244 friend class internal::FunctionCallbackArguments;
2192 static const int kDataIndex = -1; 2245 friend class internal::CustomArguments<FunctionCallbackInfo>;
2193 static const int kCalleeIndex = -2; 2246 static const int kReturnValueIndex = 0;
2194 static const int kHolderIndex = -3; 2247 static const int kIsolateIndex = -1;
2248 static const int kDataIndex = -2;
2249 static const int kCalleeIndex = -3;
2250 static const int kHolderIndex = -4;
2251 static const int kArgsLength = 5;
2195 2252
2196 friend class ImplementationUtilities; 2253 V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args,
2197 V8_INLINE(Arguments(internal::Object** implicit_args,
2198 internal::Object** values, 2254 internal::Object** values,
2199 int length, 2255 int length,
2200 bool is_construct_call)); 2256 bool is_construct_call));
2201 internal::Object** implicit_args_; 2257 internal::Object** implicit_args_;
2202 internal::Object** values_; 2258 internal::Object** values_;
2203 int length_; 2259 int length_;
2204 bool is_construct_call_; 2260 bool is_construct_call_;
2205 }; 2261 };
2206 2262
2207 2263
2264 class V8EXPORT Arguments : public FunctionCallbackInfo<Value> {
2265 private:
2266 friend class internal::FunctionCallbackArguments;
2267 V8_INLINE(Arguments(internal::Object** implicit_args,
2268 internal::Object** values,
2269 int length,
2270 bool is_construct_call));
2271 };
2272
2208 /** 2273 /**
2209 * The information passed to an accessor callback about the context 2274 * The information passed to a property callback about the context
2210 * of the property access. 2275 * of the property access.
2211 */ 2276 */
2212 class V8EXPORT AccessorInfo { 2277 template<typename T>
2278 class V8EXPORT PropertyCallbackInfo {
2213 public: 2279 public:
2214 V8_INLINE(AccessorInfo(internal::Object** args))
2215 : args_(args) { }
2216 V8_INLINE(Isolate* GetIsolate() const); 2280 V8_INLINE(Isolate* GetIsolate() const);
2217 V8_INLINE(Local<Value> Data() const); 2281 V8_INLINE(Local<Value> Data() const);
2218 V8_INLINE(Local<Object> This() const); 2282 V8_INLINE(Local<Object> This() const);
2219 V8_INLINE(Local<Object> Holder() const); 2283 V8_INLINE(Local<Object> Holder() const);
2284 V8_INLINE(ReturnValue<T> GetReturnValue() const);
2220 2285
2221 private: 2286 protected:
2287 friend class internal::PropertyCallbackArguments;
2288 friend class internal::CustomArguments<PropertyCallbackInfo>;
2289 static const int kThisIndex = 0;
2290 static const int kHolderIndex = -1;
2291 static const int kDataIndex = -2;
2292 static const int kIsolateIndex = -3;
2293 static const int kReturnValueIndex = -4;
2294 static const int kArgsLength = 5;
2295
2296 V8_INLINE(PropertyCallbackInfo(internal::Object** args))
2297 : args_(args) { }
2222 internal::Object** args_; 2298 internal::Object** args_;
2223 }; 2299 };
2224 2300
2225 2301
2302 class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> {
2303 private:
2304 friend class internal::PropertyCallbackArguments;
2305 V8_INLINE(AccessorInfo(internal::Object** args))
2306 : PropertyCallbackInfo<Value>(args) { }
2307 };
2308
2309
2226 typedef Handle<Value> (*InvocationCallback)(const Arguments& args); 2310 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
2311 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
2227 2312
2228 /** 2313 /**
2229 * NamedProperty[Getter|Setter] are used as interceptors on object. 2314 * NamedProperty[Getter|Setter] are used as interceptors on object.
2230 * See ObjectTemplate::SetNamedPropertyHandler. 2315 * See ObjectTemplate::SetNamedPropertyHandler.
2231 */ 2316 */
2232 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, 2317 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
2233 const AccessorInfo& info); 2318 const AccessorInfo& info);
2319 typedef void (*NamedPropertyGetterCallback)(
2320 Local<String> property,
2321 const PropertyCallbackInfo<Value>& info);
2234 2322
2235 2323
2236 /** 2324 /**
2237 * Returns the value if the setter intercepts the request. 2325 * Returns the value if the setter intercepts the request.
2238 * Otherwise, returns an empty handle. 2326 * Otherwise, returns an empty handle.
2239 */ 2327 */
2240 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, 2328 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
2241 Local<Value> value, 2329 Local<Value> value,
2242 const AccessorInfo& info); 2330 const AccessorInfo& info);
2331 typedef void (*NamedPropertySetterCallback)(
2332 Local<String> property,
2333 Local<Value> value,
2334 const PropertyCallbackInfo<Value>& info);
2335
2243 2336
2244 /** 2337 /**
2245 * Returns a non-empty handle if the interceptor intercepts the request. 2338 * Returns a non-empty handle if the interceptor intercepts the request.
2246 * The result is an integer encoding property attributes (like v8::None, 2339 * The result is an integer encoding property attributes (like v8::None,
2247 * v8::DontEnum, etc.) 2340 * v8::DontEnum, etc.)
2248 */ 2341 */
2249 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, 2342 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
2250 const AccessorInfo& info); 2343 const AccessorInfo& info);
2344 typedef void (*NamedPropertyQueryCallback)(
2345 Local<String> property,
2346 const PropertyCallbackInfo<Integer>& info);
2251 2347
2252 2348
2253 /** 2349 /**
2254 * Returns a non-empty handle if the deleter intercepts the request. 2350 * Returns a non-empty handle if the deleter intercepts the request.
2255 * The return value is true if the property could be deleted and false 2351 * The return value is true if the property could be deleted and false
2256 * otherwise. 2352 * otherwise.
2257 */ 2353 */
2258 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, 2354 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
2259 const AccessorInfo& info); 2355 const AccessorInfo& info);
2356 typedef void (*NamedPropertyDeleterCallback)(
2357 Local<String> property,
2358 const PropertyCallbackInfo<Boolean>& info);
2359
2260 2360
2261 /** 2361 /**
2262 * Returns an array containing the names of the properties the named 2362 * Returns an array containing the names of the properties the named
2263 * property getter intercepts. 2363 * property getter intercepts.
2264 */ 2364 */
2265 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); 2365 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
2366 typedef void (*NamedPropertyEnumeratorCallback)(
2367 const PropertyCallbackInfo<Array>& info);
2266 2368
2267 2369
2268 /** 2370 /**
2269 * Returns the value of the property if the getter intercepts the 2371 * Returns the value of the property if the getter intercepts the
2270 * request. Otherwise, returns an empty handle. 2372 * request. Otherwise, returns an empty handle.
2271 */ 2373 */
2272 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, 2374 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
2273 const AccessorInfo& info); 2375 const AccessorInfo& info);
2376 typedef void (*IndexedPropertyGetterCallback)(
2377 uint32_t index,
2378 const PropertyCallbackInfo<Value>& info);
2274 2379
2275 2380
2276 /** 2381 /**
2277 * Returns the value if the setter intercepts the request. 2382 * Returns the value if the setter intercepts the request.
2278 * Otherwise, returns an empty handle. 2383 * Otherwise, returns an empty handle.
2279 */ 2384 */
2280 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, 2385 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
2281 Local<Value> value, 2386 Local<Value> value,
2282 const AccessorInfo& info); 2387 const AccessorInfo& info);
2388 typedef void (*IndexedPropertySetterCallback)(
2389 uint32_t index,
2390 Local<Value> value,
2391 const PropertyCallbackInfo<Value>& info);
2283 2392
2284 2393
2285 /** 2394 /**
2286 * Returns a non-empty handle if the interceptor intercepts the request. 2395 * Returns a non-empty handle if the interceptor intercepts the request.
2287 * The result is an integer encoding property attributes. 2396 * The result is an integer encoding property attributes.
2288 */ 2397 */
2289 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, 2398 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
2290 const AccessorInfo& info); 2399 const AccessorInfo& info);
2400 typedef void (*IndexedPropertyQueryCallback)(
2401 uint32_t index,
2402 const PropertyCallbackInfo<Integer>& info);
2403
2291 2404
2292 /** 2405 /**
2293 * Returns a non-empty handle if the deleter intercepts the request. 2406 * Returns a non-empty handle if the deleter intercepts the request.
2294 * The return value is true if the property could be deleted and false 2407 * The return value is true if the property could be deleted and false
2295 * otherwise. 2408 * otherwise.
2296 */ 2409 */
2297 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, 2410 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
2298 const AccessorInfo& info); 2411 const AccessorInfo& info);
2412 typedef void (*IndexedPropertyDeleterCallback)(
2413 uint32_t index,
2414 const PropertyCallbackInfo<Boolean>& info);
2415
2299 2416
2300 /** 2417 /**
2301 * Returns an array containing the indices of the properties the 2418 * Returns an array containing the indices of the properties the
2302 * indexed property getter intercepts. 2419 * indexed property getter intercepts.
2303 */ 2420 */
2304 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); 2421 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
2422 typedef void (*IndexedPropertyEnumeratorCallback)(
2423 const PropertyCallbackInfo<Array>& info);
2305 2424
2306 2425
2307 /** 2426 /**
2308 * Access type specification. 2427 * Access type specification.
2309 */ 2428 */
2310 enum AccessType { 2429 enum AccessType {
2311 ACCESS_GET, 2430 ACCESS_GET,
2312 ACCESS_SET, 2431 ACCESS_SET,
2313 ACCESS_HAS, 2432 ACCESS_HAS,
2314 ACCESS_DELETE, 2433 ACCESS_DELETE,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2424 * 2543 *
2425 * \code 2544 * \code
2426 * child_func.prototype.__proto__ == function.prototype; 2545 * child_func.prototype.__proto__ == function.prototype;
2427 * child_instance.instance_accessor calls 'InstanceAccessorCallback' 2546 * child_instance.instance_accessor calls 'InstanceAccessorCallback'
2428 * child_instance.instance_property == 3; 2547 * child_instance.instance_property == 3;
2429 * \endcode 2548 * \endcode
2430 */ 2549 */
2431 class V8EXPORT FunctionTemplate : public Template { 2550 class V8EXPORT FunctionTemplate : public Template {
2432 public: 2551 public:
2433 /** Creates a function template.*/ 2552 /** Creates a function template.*/
2553 // TODO(dcarney): deprecate
2434 static Local<FunctionTemplate> New( 2554 static Local<FunctionTemplate> New(
2435 InvocationCallback callback = 0, 2555 InvocationCallback callback = 0,
2436 Handle<Value> data = Handle<Value>(), 2556 Handle<Value> data = Handle<Value>(),
2437 Handle<Signature> signature = Handle<Signature>(), 2557 Handle<Signature> signature = Handle<Signature>(),
2438 int length = 0); 2558 int length = 0);
2559 static Local<FunctionTemplate> New(
2560 FunctionCallback callback, // TODO(dcarney): add back default param.
2561 Handle<Value> data = Handle<Value>(),
2562 Handle<Signature> signature = Handle<Signature>(),
2563 int length = 0);
2564
2439 /** Returns the unique function instance in the current execution context.*/ 2565 /** Returns the unique function instance in the current execution context.*/
2440 Local<Function> GetFunction(); 2566 Local<Function> GetFunction();
2441 2567
2442 /** 2568 /**
2443 * Set the call-handler callback for a FunctionTemplate. This 2569 * Set the call-handler callback for a FunctionTemplate. This
2444 * callback is called whenever the function created from this 2570 * callback is called whenever the function created from this
2445 * FunctionTemplate is called. 2571 * FunctionTemplate is called.
2446 */ 2572 */
2573 // TODO(dcarney): deprecate
2447 void SetCallHandler(InvocationCallback callback, 2574 void SetCallHandler(InvocationCallback callback,
2448 Handle<Value> data = Handle<Value>()); 2575 Handle<Value> data = Handle<Value>());
2576 void SetCallHandler(FunctionCallback callback,
2577 Handle<Value> data = Handle<Value>());
2449 2578
2450 /** Set the predefined length property for the FunctionTemplate. */ 2579 /** Set the predefined length property for the FunctionTemplate. */
2451 void SetLength(int length); 2580 void SetLength(int length);
2452 2581
2453 /** Get the InstanceTemplate. */ 2582 /** Get the InstanceTemplate. */
2454 Local<ObjectTemplate> InstanceTemplate(); 2583 Local<ObjectTemplate> InstanceTemplate();
2455 2584
2456 /** Causes the function template to inherit from a parent function template.*/ 2585 /** Causes the function template to inherit from a parent function template.*/
2457 void Inherit(Handle<FunctionTemplate> parent); 2586 void Inherit(Handle<FunctionTemplate> parent);
2458 2587
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 void ReadOnlyPrototype(); 2619 void ReadOnlyPrototype();
2491 2620
2492 /** 2621 /**
2493 * Returns true if the given object is an instance of this function 2622 * Returns true if the given object is an instance of this function
2494 * template. 2623 * template.
2495 */ 2624 */
2496 bool HasInstance(Handle<Value> object); 2625 bool HasInstance(Handle<Value> object);
2497 2626
2498 private: 2627 private:
2499 FunctionTemplate(); 2628 FunctionTemplate();
2500 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2501 NamedPropertySetter setter,
2502 NamedPropertyQuery query,
2503 NamedPropertyDeleter remover,
2504 NamedPropertyEnumerator enumerator,
2505 Handle<Value> data);
2506 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2507 IndexedPropertySetter setter,
2508 IndexedPropertyQuery query,
2509 IndexedPropertyDeleter remover,
2510 IndexedPropertyEnumerator enumerator,
2511 Handle<Value> data);
2512 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
2513 Handle<Value> data);
2514
2515 friend class Context; 2629 friend class Context;
2516 friend class ObjectTemplate; 2630 friend class ObjectTemplate;
2517 }; 2631 };
2518 2632
2519 2633
2520 /** 2634 /**
2521 * An ObjectTemplate is used to create objects at runtime. 2635 * An ObjectTemplate is used to create objects at runtime.
2522 * 2636 *
2523 * Properties added to an ObjectTemplate are added to each object 2637 * Properties added to an ObjectTemplate are added to each object
2524 * created from the ObjectTemplate. 2638 * created from the ObjectTemplate.
(...skipping 28 matching lines...) Expand all
2553 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all 2667 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
2554 * cross-context access. 2668 * cross-context access.
2555 * \param attribute The attributes of the property for which an accessor 2669 * \param attribute The attributes of the property for which an accessor
2556 * is added. 2670 * is added.
2557 * \param signature The signature describes valid receivers for the accessor 2671 * \param signature The signature describes valid receivers for the accessor
2558 * and is used to perform implicit instance checks against them. If the 2672 * and is used to perform implicit instance checks against them. If the
2559 * receiver is incompatible (i.e. is not an instance of the constructor as 2673 * receiver is incompatible (i.e. is not an instance of the constructor as
2560 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is 2674 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
2561 * thrown and no callback is invoked. 2675 * thrown and no callback is invoked.
2562 */ 2676 */
2677 // TODO(dcarney): deprecate
2563 void SetAccessor(Handle<String> name, 2678 void SetAccessor(Handle<String> name,
2564 AccessorGetter getter, 2679 AccessorGetter getter,
2565 AccessorSetter setter = 0, 2680 AccessorSetter setter = 0,
2566 Handle<Value> data = Handle<Value>(), 2681 Handle<Value> data = Handle<Value>(),
2567 AccessControl settings = DEFAULT, 2682 AccessControl settings = DEFAULT,
2568 PropertyAttribute attribute = None, 2683 PropertyAttribute attribute = None,
2569 Handle<AccessorSignature> signature = 2684 Handle<AccessorSignature> signature =
2570 Handle<AccessorSignature>()); 2685 Handle<AccessorSignature>());
2686 void SetAccessor(Handle<String> name,
2687 AccessorGetterCallback getter,
2688 AccessorSetterCallback setter = 0,
2689 Handle<Value> data = Handle<Value>(),
2690 AccessControl settings = DEFAULT,
2691 PropertyAttribute attribute = None,
2692 Handle<AccessorSignature> signature =
2693 Handle<AccessorSignature>());
2571 2694
2572 // This function is not yet stable and should not be used at this time. 2695 // This function is not yet stable and should not be used at this time.
2573 bool SetAccessor(Handle<String> name, 2696 bool SetAccessor(Handle<String> name,
2574 Handle<DeclaredAccessorDescriptor> descriptor, 2697 Handle<DeclaredAccessorDescriptor> descriptor,
2575 AccessControl settings = DEFAULT, 2698 AccessControl settings = DEFAULT,
2576 PropertyAttribute attribute = None, 2699 PropertyAttribute attribute = None,
2577 Handle<AccessorSignature> signature = 2700 Handle<AccessorSignature> signature =
2578 Handle<AccessorSignature>()); 2701 Handle<AccessorSignature>());
2579 2702
2580 /** 2703 /**
2581 * Sets a named property handler on the object template. 2704 * Sets a named property handler on the object template.
2582 * 2705 *
2583 * Whenever a named property is accessed on objects created from 2706 * Whenever a named property is accessed on objects created from
2584 * this object template, the provided callback is invoked instead of 2707 * this object template, the provided callback is invoked instead of
2585 * accessing the property directly on the JavaScript object. 2708 * accessing the property directly on the JavaScript object.
2586 * 2709 *
2587 * \param getter The callback to invoke when getting a property. 2710 * \param getter The callback to invoke when getting a property.
2588 * \param setter The callback to invoke when setting a property. 2711 * \param setter The callback to invoke when setting a property.
2589 * \param query The callback to invoke to check if a property is present, 2712 * \param query The callback to invoke to check if a property is present,
2590 * and if present, get its attributes. 2713 * and if present, get its attributes.
2591 * \param deleter The callback to invoke when deleting a property. 2714 * \param deleter The callback to invoke when deleting a property.
2592 * \param enumerator The callback to invoke to enumerate all the named 2715 * \param enumerator The callback to invoke to enumerate all the named
2593 * properties of an object. 2716 * properties of an object.
2594 * \param data A piece of data that will be passed to the callbacks 2717 * \param data A piece of data that will be passed to the callbacks
2595 * whenever they are invoked. 2718 * whenever they are invoked.
2596 */ 2719 */
2720 // TODO(dcarney): deprecate
2597 void SetNamedPropertyHandler(NamedPropertyGetter getter, 2721 void SetNamedPropertyHandler(NamedPropertyGetter getter,
2598 NamedPropertySetter setter = 0, 2722 NamedPropertySetter setter = 0,
2599 NamedPropertyQuery query = 0, 2723 NamedPropertyQuery query = 0,
2600 NamedPropertyDeleter deleter = 0, 2724 NamedPropertyDeleter deleter = 0,
2601 NamedPropertyEnumerator enumerator = 0, 2725 NamedPropertyEnumerator enumerator = 0,
2602 Handle<Value> data = Handle<Value>()); 2726 Handle<Value> data = Handle<Value>());
2727 void SetNamedPropertyHandler(
2728 NamedPropertyGetterCallback getter,
2729 NamedPropertySetterCallback setter = 0,
2730 NamedPropertyQueryCallback query = 0,
2731 NamedPropertyDeleterCallback deleter = 0,
2732 NamedPropertyEnumeratorCallback enumerator = 0,
2733 Handle<Value> data = Handle<Value>());
2603 2734
2604 /** 2735 /**
2605 * Sets an indexed property handler on the object template. 2736 * Sets an indexed property handler on the object template.
2606 * 2737 *
2607 * Whenever an indexed property is accessed on objects created from 2738 * Whenever an indexed property is accessed on objects created from
2608 * this object template, the provided callback is invoked instead of 2739 * this object template, the provided callback is invoked instead of
2609 * accessing the property directly on the JavaScript object. 2740 * accessing the property directly on the JavaScript object.
2610 * 2741 *
2611 * \param getter The callback to invoke when getting a property. 2742 * \param getter The callback to invoke when getting a property.
2612 * \param setter The callback to invoke when setting a property. 2743 * \param setter The callback to invoke when setting a property.
2613 * \param query The callback to invoke to check if an object has a property. 2744 * \param query The callback to invoke to check if an object has a property.
2614 * \param deleter The callback to invoke when deleting a property. 2745 * \param deleter The callback to invoke when deleting a property.
2615 * \param enumerator The callback to invoke to enumerate all the indexed 2746 * \param enumerator The callback to invoke to enumerate all the indexed
2616 * properties of an object. 2747 * properties of an object.
2617 * \param data A piece of data that will be passed to the callbacks 2748 * \param data A piece of data that will be passed to the callbacks
2618 * whenever they are invoked. 2749 * whenever they are invoked.
2619 */ 2750 */
2751 // TODO(dcarney): deprecate
2620 void SetIndexedPropertyHandler(IndexedPropertyGetter getter, 2752 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
2621 IndexedPropertySetter setter = 0, 2753 IndexedPropertySetter setter = 0,
2622 IndexedPropertyQuery query = 0, 2754 IndexedPropertyQuery query = 0,
2623 IndexedPropertyDeleter deleter = 0, 2755 IndexedPropertyDeleter deleter = 0,
2624 IndexedPropertyEnumerator enumerator = 0, 2756 IndexedPropertyEnumerator enumerator = 0,
2625 Handle<Value> data = Handle<Value>()); 2757 Handle<Value> data = Handle<Value>());
2758 void SetIndexedPropertyHandler(
2759 IndexedPropertyGetterCallback getter,
2760 IndexedPropertySetterCallback setter = 0,
2761 IndexedPropertyQueryCallback query = 0,
2762 IndexedPropertyDeleterCallback deleter = 0,
2763 IndexedPropertyEnumeratorCallback enumerator = 0,
2764 Handle<Value> data = Handle<Value>());
2626 2765
2627 /** 2766 /**
2628 * Sets the callback to be used when calling instances created from 2767 * Sets the callback to be used when calling instances created from
2629 * this template as a function. If no callback is set, instances 2768 * this template as a function. If no callback is set, instances
2630 * behave like normal JavaScript objects that cannot be called as a 2769 * behave like normal JavaScript objects that cannot be called as a
2631 * function. 2770 * function.
2632 */ 2771 */
2772 // TODO(dcarney): deprecate
2633 void SetCallAsFunctionHandler(InvocationCallback callback, 2773 void SetCallAsFunctionHandler(InvocationCallback callback,
2634 Handle<Value> data = Handle<Value>()); 2774 Handle<Value> data = Handle<Value>());
2775 void SetCallAsFunctionHandler(FunctionCallback callback,
2776 Handle<Value> data = Handle<Value>());
2635 2777
2636 /** 2778 /**
2637 * Mark object instances of the template as undetectable. 2779 * Mark object instances of the template as undetectable.
2638 * 2780 *
2639 * In many ways, undetectable objects behave as though they are not 2781 * In many ways, undetectable objects behave as though they are not
2640 * there. They behave like 'undefined' in conditionals and when 2782 * there. They behave like 'undefined' in conditionals and when
2641 * printed. However, properties can be accessed and called as on 2783 * printed. However, properties can be accessed and called as on
2642 * normal objects. 2784 * normal objects.
2643 */ 2785 */
2644 void MarkAsUndetectable(); 2786 void MarkAsUndetectable();
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
4763 template <class T> 4905 template <class T>
4764 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { 4906 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const {
4765 typedef internal::Internals I; 4907 typedef internal::Internals I;
4766 if (this->IsEmpty()) return 0; 4908 if (this->IsEmpty()) return 0;
4767 if (!I::IsInitialized(isolate)) return 0; 4909 if (!I::IsInitialized(isolate)) return 0;
4768 internal::Object** obj = reinterpret_cast<internal::Object**>(**this); 4910 internal::Object** obj = reinterpret_cast<internal::Object**>(**this);
4769 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 4911 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
4770 return *reinterpret_cast<uint16_t*>(addr); 4912 return *reinterpret_cast<uint16_t*>(addr);
4771 } 4913 }
4772 4914
4773 Arguments::Arguments(internal::Object** implicit_args, 4915 template<typename T>
4774 internal::Object** values, int length, 4916 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
4775 bool is_construct_call) 4917
4918 template<typename T>
4919 void ReturnValue<T>::Set(Persistent<T> handle) {
4920 *value_ = *reinterpret_cast<internal::Object**>(*handle);
4921 }
4922
4923 template<typename T>
4924 void ReturnValue<T>::Set(Handle<T> handle) {
4925 *value_ = *reinterpret_cast<internal::Object**>(*handle);
4926 }
4927
4928 template<typename T>
4929 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
4930 internal::Object** values,
4931 int length,
4932 bool is_construct_call)
4776 : implicit_args_(implicit_args), 4933 : implicit_args_(implicit_args),
4777 values_(values), 4934 values_(values),
4778 length_(length), 4935 length_(length),
4779 is_construct_call_(is_construct_call) { } 4936 is_construct_call_(is_construct_call) { }
4780 4937
4781 4938
4782 Local<Value> Arguments::operator[](int i) const { 4939 Arguments::Arguments(internal::Object** args,
4940 internal::Object** values,
4941 int length,
4942 bool is_construct_call)
4943 : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { }
4944
4945
4946 template<typename T>
4947 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
4783 if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); 4948 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
4784 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); 4949 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
4785 } 4950 }
4786 4951
4787 4952
4788 Local<Function> Arguments::Callee() const { 4953 template<typename T>
4954 Local<Function> FunctionCallbackInfo<T>::Callee() const {
4789 return Local<Function>(reinterpret_cast<Function*>( 4955 return Local<Function>(reinterpret_cast<Function*>(
4790 &implicit_args_[kCalleeIndex])); 4956 &implicit_args_[kCalleeIndex]));
4791 } 4957 }
4792 4958
4793 4959
4794 Local<Object> Arguments::This() const { 4960 template<typename T>
4961 Local<Object> FunctionCallbackInfo<T>::This() const {
4795 return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); 4962 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
4796 } 4963 }
4797 4964
4798 4965
4799 Local<Object> Arguments::Holder() const { 4966 template<typename T>
4967 Local<Object> FunctionCallbackInfo<T>::Holder() const {
4800 return Local<Object>(reinterpret_cast<Object*>( 4968 return Local<Object>(reinterpret_cast<Object*>(
4801 &implicit_args_[kHolderIndex])); 4969 &implicit_args_[kHolderIndex]));
4802 } 4970 }
4803 4971
4804 4972
4805 Local<Value> Arguments::Data() const { 4973 template<typename T>
4974 Local<Value> FunctionCallbackInfo<T>::Data() const {
4806 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); 4975 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
4807 } 4976 }
4808 4977
4809 4978
4810 Isolate* Arguments::GetIsolate() const { 4979 template<typename T>
4980 Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
4811 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); 4981 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
4812 } 4982 }
4813 4983
4814 4984
4815 bool Arguments::IsConstructCall() const { 4985 template<typename T>
4986 ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
4987 return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
4988 }
4989
4990
4991 template<typename T>
4992 bool FunctionCallbackInfo<T>::IsConstructCall() const {
4816 return is_construct_call_; 4993 return is_construct_call_;
4817 } 4994 }
4818 4995
4819 4996
4820 int Arguments::Length() const { 4997 template<typename T>
4998 int FunctionCallbackInfo<T>::Length() const {
4821 return length_; 4999 return length_;
4822 } 5000 }
4823 5001
4824 5002
4825 template <class T> 5003 template <class T>
4826 Local<T> HandleScope::Close(Handle<T> value) { 5004 Local<T> HandleScope::Close(Handle<T> value) {
4827 internal::Object** before = reinterpret_cast<internal::Object**>(*value); 5005 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
4828 internal::Object** after = RawClose(before); 5006 internal::Object** after = RawClose(before);
4829 return Local<T>(reinterpret_cast<T*>(after)); 5007 return Local<T>(reinterpret_cast<T*>(after));
4830 } 5008 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
5119 5297
5120 5298
5121 External* External::Cast(v8::Value* value) { 5299 External* External::Cast(v8::Value* value) {
5122 #ifdef V8_ENABLE_CHECKS 5300 #ifdef V8_ENABLE_CHECKS
5123 CheckCast(value); 5301 CheckCast(value);
5124 #endif 5302 #endif
5125 return static_cast<External*>(value); 5303 return static_cast<External*>(value);
5126 } 5304 }
5127 5305
5128 5306
5129 Isolate* AccessorInfo::GetIsolate() const { 5307 template<typename T>
5130 return *reinterpret_cast<Isolate**>(&args_[-3]); 5308 Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
5309 return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
5131 } 5310 }
5132 5311
5133 5312
5134 Local<Value> AccessorInfo::Data() const { 5313 template<typename T>
5135 return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); 5314 Local<Value> PropertyCallbackInfo<T>::Data() const {
5315 return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
5136 } 5316 }
5137 5317
5138 5318
5139 Local<Object> AccessorInfo::This() const { 5319 template<typename T>
5140 return Local<Object>(reinterpret_cast<Object*>(&args_[0])); 5320 Local<Object> PropertyCallbackInfo<T>::This() const {
5321 return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
5141 } 5322 }
5142 5323
5143 5324
5144 Local<Object> AccessorInfo::Holder() const { 5325 template<typename T>
5145 return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); 5326 Local<Object> PropertyCallbackInfo<T>::Holder() const {
5327 return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
5146 } 5328 }
5147 5329
5148 5330
5331 template<typename T>
5332 ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
5333 return ReturnValue<T>(&args_[kReturnValueIndex]);
5334 }
5335
5336
5149 Handle<Primitive> Undefined(Isolate* isolate) { 5337 Handle<Primitive> Undefined(Isolate* isolate) {
5150 typedef internal::Object* S; 5338 typedef internal::Object* S;
5151 typedef internal::Internals I; 5339 typedef internal::Internals I;
5152 if (!I::IsInitialized(isolate)) return Undefined(); 5340 if (!I::IsInitialized(isolate)) return Undefined();
5153 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); 5341 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
5154 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); 5342 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
5155 } 5343 }
5156 5344
5157 5345
5158 Handle<Primitive> Null(Isolate* isolate) { 5346 Handle<Primitive> Null(Isolate* isolate) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5229 5417
5230 5418
5231 } // namespace v8 5419 } // namespace v8
5232 5420
5233 5421
5234 #undef V8EXPORT 5422 #undef V8EXPORT
5235 #undef TYPE_CHECK 5423 #undef TYPE_CHECK
5236 5424
5237 5425
5238 #endif // V8_H_ 5426 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/x64/macro-assembler-x64.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698