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

Unified Diff: include/v8.h

Issue 341453003: Support symbol-named properties in API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 2739e070b634cac24804eb2e8813a7d451b13fb0..c6cc8f6066f161353fa04c28c9e290745a7e438b 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -77,6 +77,7 @@ class ImplementationUtilities;
class Int32;
class Integer;
class Isolate;
+class Name;
class Number;
class NumberObject;
class Object;
@@ -1329,6 +1330,12 @@ class V8_EXPORT Value : public Data {
bool IsFalse() const;
/**
+ * Returns true if this value is a symbol or a string.
+ * This is an experimental feature.
+ */
+ bool IsName() const;
+
+ /**
* Returns true if this value is an instance of the String type.
* See ECMA-262 8.4.
*/
@@ -1556,9 +1563,20 @@ class V8_EXPORT Boolean : public Primitive {
/**
+ * A superclass for symbols and strings.
+ */
+class V8_EXPORT Name : public Primitive {
+ public:
+ V8_INLINE static Name* Cast(v8::Value* obj);
+ private:
+ static void CheckCast(v8::Value* obj);
+};
+
+
+/**
* A JavaScript string value (ECMA-262, 4.3.17).
*/
-class V8_EXPORT String : public Primitive {
+class V8_EXPORT String : public Name {
public:
enum Encoding {
UNKNOWN_ENCODING = 0x1,
@@ -1897,7 +1915,7 @@ class V8_EXPORT String : public Primitive {
*
* This is an experimental feature. Use at your own risk.
*/
-class V8_EXPORT Symbol : public Primitive {
+class V8_EXPORT Symbol : public Name {
public:
// Returns the print name string of the symbol, or undefined if none.
Local<Value> Name() const;
@@ -2041,12 +2059,19 @@ enum ExternalArrayType {
typedef void (*AccessorGetterCallback)(
Local<String> property,
const PropertyCallbackInfo<Value>& info);
+typedef void (*AccessorSymbolGetterCallback)(
+ Local<Symbol> property,
+ const PropertyCallbackInfo<Value>& info);
typedef void (*AccessorSetterCallback)(
Local<String> property,
Local<Value> value,
const PropertyCallbackInfo<void>& info);
+typedef void (*AccessorSymbolSetterCallback)(
+ Local<Symbol> property,
+ Local<Value> value,
+ const PropertyCallbackInfo<void>& info);
/**
@@ -2118,14 +2143,20 @@ class V8_EXPORT Object : public Value {
Handle<Value> data = Handle<Value>(),
AccessControl settings = DEFAULT,
PropertyAttribute attribute = None);
+ bool SetAccessor(Handle<Symbol> name,
+ AccessorSymbolGetterCallback getter,
+ AccessorSymbolSetterCallback setter = 0,
+ Handle<Value> data = Handle<Value>(),
+ AccessControl settings = DEFAULT,
+ PropertyAttribute attribute = None);
// This function is not yet stable and should not be used at this time.
- bool SetDeclaredAccessor(Local<String> name,
+ bool SetDeclaredAccessor(Local<Name> name,
Local<DeclaredAccessorDescriptor> descriptor,
PropertyAttribute attribute = None,
AccessControl settings = DEFAULT);
- void SetAccessorProperty(Local<String> name,
+ void SetAccessorProperty(Local<Name> name,
Local<Function> getter,
Handle<Function> setter = Handle<Function>(),
PropertyAttribute attribute = None,
@@ -3133,12 +3164,12 @@ class V8_EXPORT External : public Value {
class V8_EXPORT Template : public Data {
public:
/** Adds a property to each instance created by this template.*/
- void Set(Handle<String> name, Handle<Data> value,
+ void Set(Handle<Name> name, Handle<Data> value,
PropertyAttribute attributes = None);
V8_INLINE void Set(Isolate* isolate, const char* name, Handle<Data> value);
void SetAccessorProperty(
- Local<String> name,
+ Local<Name> name,
Local<FunctionTemplate> getter = Local<FunctionTemplate>(),
Local<FunctionTemplate> setter = Local<FunctionTemplate>(),
PropertyAttribute attribute = None,
@@ -3180,9 +3211,18 @@ class V8_EXPORT Template : public Data {
Local<AccessorSignature> signature =
Local<AccessorSignature>(),
AccessControl settings = DEFAULT);
+ void SetNativeDataProperty(Local<Symbol> name,
+ AccessorSymbolGetterCallback getter,
+ AccessorSymbolSetterCallback setter = 0,
+ // TODO(dcarney): gcc can't handle Local below
+ Handle<Value> data = Handle<Value>(),
+ PropertyAttribute attribute = None,
+ Local<AccessorSignature> signature =
+ Local<AccessorSignature>(),
+ AccessControl settings = DEFAULT);
// This function is not yet stable and should not be used at this time.
- bool SetDeclaredAccessor(Local<String> name,
+ bool SetDeclaredAccessor(Local<Name> name,
Local<DeclaredAccessorDescriptor> descriptor,
PropertyAttribute attribute = None,
Local<AccessorSignature> signature =
@@ -3244,6 +3284,55 @@ typedef void (*NamedPropertyEnumeratorCallback)(
const PropertyCallbackInfo<Array>& info);
+// TODO(wingo): Deprecate and remove previous typedefs, and replace
+// GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
+/**
+ * GenericNamedProperty[Getter|Setter] are used as interceptors on object.
+ * See ObjectTemplate::SetGenericNamedPropertyHandler.
+ */
+typedef void (*GenericNamedPropertyGetterCallback)(
+ Local<Name> property,
+ const PropertyCallbackInfo<Value>& info);
+
+
+/**
+ * Returns the value if the setter intercepts the request.
+ * Otherwise, returns an empty handle.
+ */
+typedef void (*GenericNamedPropertySetterCallback)(
+ Local<Name> property,
+ Local<Value> value,
+ const PropertyCallbackInfo<Value>& info);
+
+
+/**
+ * Returns a non-empty handle if the interceptor intercepts the request.
+ * The result is an integer encoding property attributes (like v8::None,
+ * v8::DontEnum, etc.)
+ */
+typedef void (*GenericNamedPropertyQueryCallback)(
+ Local<Name> property,
+ const PropertyCallbackInfo<Integer>& info);
+
+
+/**
+ * Returns a non-empty handle if the deleter intercepts the request.
+ * The return value is true if the property could be deleted and false
+ * otherwise.
+ */
+typedef void (*GenericNamedPropertyDeleterCallback)(
+ Local<Name> property,
+ const PropertyCallbackInfo<Boolean>& info);
+
+
+/**
+ * Returns an array containing the names of the properties the named
+ * property getter intercepts.
+ */
+typedef void (*GenericNamedPropertyEnumeratorCallback)(
+ const PropertyCallbackInfo<Array>& info);
+
+
/**
* Returns the value of the property if the getter intercepts the
* request. Otherwise, returns an empty handle.
@@ -3551,10 +3640,48 @@ class V8_EXPORT ObjectTemplate : public Template {
Handle<AccessorSignature>());
/**
+ * A version of SetAccessor for properties whose names are symbols.
+ *
+ * Whenever the property with the given name is accessed on objects
+ * created from this ObjectTemplate the getter and setter callbacks
+ * are called instead of getting and setting the property directly
+ * on the JavaScript object.
+ *
+ * \param name The name of the property for which an accessor is added.
+ * \param getter The callback to invoke when getting the property.
+ * \param setter The callback to invoke when setting the property.
+ * \param data A piece of data that will be passed to the getter and setter
+ * callbacks whenever they are invoked.
+ * \param settings Access control settings for the accessor. This is a bit
+ * field consisting of one of more of
+ * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
+ * The default is to not allow cross-context access.
+ * ALL_CAN_READ means that all cross-context reads are allowed.
+ * ALL_CAN_WRITE means that all cross-context writes are allowed.
+ * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
+ * cross-context access.
+ * \param attribute The attributes of the property for which an accessor
+ * is added.
+ * \param signature The signature describes valid receivers for the accessor
+ * and is used to perform implicit instance checks against them. If the
+ * receiver is incompatible (i.e. is not an instance of the constructor as
+ * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
+ * thrown and no callback is invoked.
+ */
+ void SetAccessor(Handle<Symbol> name,
+ AccessorSymbolGetterCallback getter,
+ AccessorSymbolSetterCallback setter = 0,
+ Handle<Value> data = Handle<Value>(),
+ AccessControl settings = DEFAULT,
+ PropertyAttribute attribute = None,
+ Handle<AccessorSignature> signature =
+ Handle<AccessorSignature>());
+
+ /**
* Sets a named property handler on the object template.
*
- * Whenever a named property is accessed on objects created from
- * this object template, the provided callback is invoked instead of
+ * Whenever a property whose name is a string is accessed on objects created
+ * from this object template, the provided callback is invoked instead of
* accessing the property directly on the JavaScript object.
*
* \param getter The callback to invoke when getting a property.
@@ -3576,6 +3703,34 @@ class V8_EXPORT ObjectTemplate : public Template {
Handle<Value> data = Handle<Value>());
/**
+ * Sets a named property handler on the object template.
+ *
+ * Whenever a property is accessed on objects created from this object
+ * template, the provided callback is invoked instead of accessing the
+ * property directly on the JavaScript object.
+ *
+ * Unlike SetNamedPropertyHandler, this version also intercepts values whose
+ * names are symbols.
+ *
+ * \param getter The callback to invoke when getting a property.
+ * \param setter The callback to invoke when setting a property.
+ * \param query The callback to invoke to check if a property is present,
+ * and if present, get its attributes.
+ * \param deleter The callback to invoke when deleting a property.
+ * \param enumerator The callback to invoke to enumerate all the named
+ * properties of an object.
+ * \param data A piece of data that will be passed to the callbacks
+ * whenever they are invoked.
+ */
+ void SetGenericNamedPropertyHandler(
+ GenericNamedPropertyGetterCallback getter,
+ GenericNamedPropertySetterCallback setter = 0,
+ GenericNamedPropertyQueryCallback query = 0,
+ GenericNamedPropertyDeleterCallback deleter = 0,
+ GenericNamedPropertyEnumeratorCallback enumerator = 0,
+ Handle<Value> data = Handle<Value>());
+
+ /**
* Sets an indexed property handler on the object template.
*
* Whenever an indexed property is accessed on objects created from
@@ -6260,6 +6415,14 @@ template <class T> Value* Value::Cast(T* value) {
}
+Name* Name::Cast(v8::Value* value) {
+#ifdef V8_ENABLE_CHECKS
+ CheckCast(value);
+#endif
+ return static_cast<Name*>(value);
+}
+
+
Symbol* Symbol::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698