Revision: 23247
Author: [email protected]
Date: Wed Aug 20 15:25:13 2014 UTC
Log: Support symbol-named properties in API
Add new "Name" type to API that is a supertype of Symbol and String.
Object::SetDeclaredAccessor, Object::SetAccessorProperty, Template::Set,
Template::SetAccessorProperty, and Template::SetDeclaredAccessor now
take a Name as the property name instead of a String.
Add Object::SetAccessor, Template::SetNativeDataProperty, and
ObjectTemplate::SetAccessor overloads that can define accessors for
symbol-named properties.
[email protected], [email protected]
BUG=v8:3394
TEST=cctest/test-api/TestSymbolProperties
LOG=Y
Review URL: https://codereview.chromium.org/459413002
http://code.google.com/p/v8/source/detail?r=23247
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/accessors.cc
/branches/bleeding_edge/src/accessors.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/api.h
/branches/bleeding_edge/src/arguments.h
/branches/bleeding_edge/src/arm64/simulator-arm64.cc
/branches/bleeding_edge/src/assembler.h
/branches/bleeding_edge/src/objects.cc
/branches/bleeding_edge/src/stub-cache.cc
/branches/bleeding_edge/test/cctest/test-alloc.cc
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Tue Aug 19 12:08:46 2014 UTC
+++ /branches/bleeding_edge/include/v8.h Wed Aug 20 15:25:13 2014 UTC
@@ -77,6 +77,7 @@
class Int32;
class Integer;
class Isolate;
+class Name;
class Number;
class NumberObject;
class Object;
@@ -1366,6 +1367,12 @@
*/
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.
@@ -1598,10 +1605,21 @@
};
+/**
+ * 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,
@@ -1940,7 +1958,7 @@
*
* 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;
@@ -2089,11 +2107,18 @@
typedef void (*AccessorGetterCallback)(
Local<String> property,
const PropertyCallbackInfo<Value>& info);
+typedef void (*AccessorNameGetterCallback)(
+ Local<Name> property,
+ const PropertyCallbackInfo<Value>& info);
typedef void (*AccessorSetterCallback)(
Local<String> property,
Local<Value> value,
+ const PropertyCallbackInfo<void>& info);
+typedef void (*AccessorNameSetterCallback)(
+ Local<Name> property,
+ Local<Value> value,
const PropertyCallbackInfo<void>& info);
@@ -2169,14 +2194,20 @@
Handle<Value> data = Handle<Value>(),
AccessControl settings = DEFAULT,
PropertyAttribute attribute = None);
+ bool SetAccessor(Handle<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback 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,
@@ -3178,12 +3209,12 @@
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,
@@ -3225,9 +3256,18 @@
Local<AccessorSignature> signature =
Local<AccessorSignature>(),
AccessControl settings = DEFAULT);
+ void SetNativeDataProperty(Local<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback 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 =
@@ -3594,12 +3634,20 @@
PropertyAttribute attribute = None,
Handle<AccessorSignature> signature =
Handle<AccessorSignature>());
+ void SetAccessor(Handle<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback 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.
@@ -6346,6 +6394,14 @@
template <class T> Value* Value::Cast(T* value) {
return static_cast<Value*>(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) {
=======================================
--- /branches/bleeding_edge/src/accessors.cc Mon Aug 11 12:57:25 2014 UTC
+++ /branches/bleeding_edge/src/accessors.cc Wed Aug 20 15:25:13 2014 UTC
@@ -23,9 +23,9 @@
Handle<AccessorInfo> Accessors::MakeAccessor(
Isolate* isolate,
- Handle<String> name,
- AccessorGetterCallback getter,
- AccessorSetterCallback setter,
+ Handle<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback setter,
PropertyAttributes attributes) {
Factory* factory = isolate->factory();
Handle<ExecutableAccessorInfo> info =
factory->NewExecutableAccessorInfo();
@@ -138,7 +138,7 @@
bool SetPropertyOnInstanceIfInherited(
Isolate* isolate, const v8::PropertyCallbackInfo<void>& info,
- v8::Local<v8::String> name, Handle<Object> value) {
+ v8::Local<v8::Name> name, Handle<Object> value) {
Handle<Object> holder = Utils::OpenHandle(*info.Holder());
Handle<Object> receiver = Utils::OpenHandle(*info.This());
if (*holder == *receiver) return false;
@@ -176,7 +176,7 @@
void Accessors::ArrayLengthGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -188,7 +188,7 @@
void Accessors::ArrayLengthSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
@@ -244,7 +244,7 @@
//
void Accessors::StringLengthGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -267,7 +267,7 @@
void Accessors::StringLengthSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -290,7 +290,7 @@
void Accessors::ScriptColumnOffsetGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -302,7 +302,7 @@
void Accessors::ScriptColumnOffsetSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -327,7 +327,7 @@
void Accessors::ScriptIdGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -339,7 +339,7 @@
void Accessors::ScriptIdSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -364,7 +364,7 @@
void Accessors::ScriptNameGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -376,7 +376,7 @@
void Accessors::ScriptNameSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -399,7 +399,7 @@
void Accessors::ScriptSourceGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -411,7 +411,7 @@
void Accessors::ScriptSourceSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -434,7 +434,7 @@
void Accessors::ScriptLineOffsetGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -446,7 +446,7 @@
void Accessors::ScriptLineOffsetSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -471,7 +471,7 @@
void Accessors::ScriptTypeGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -483,7 +483,7 @@
void Accessors::ScriptTypeSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -508,7 +508,7 @@
void Accessors::ScriptCompilationTypeGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -521,7 +521,7 @@
void Accessors::ScriptCompilationTypeSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -546,7 +546,7 @@
void Accessors::ScriptLineEndsGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -566,7 +566,7 @@
void Accessors::ScriptLineEndsSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -591,7 +591,7 @@
void Accessors::ScriptSourceUrlGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -603,7 +603,7 @@
void Accessors::ScriptSourceUrlSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -626,7 +626,7 @@
void Accessors::ScriptSourceMappingUrlGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -639,7 +639,7 @@
void Accessors::ScriptSourceMappingUrlSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -662,7 +662,7 @@
void Accessors::ScriptContextDataGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
DisallowHeapAllocation no_allocation;
@@ -674,7 +674,7 @@
void Accessors::ScriptContextDataSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -699,7 +699,7 @@
void Accessors::ScriptEvalFromScriptGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -721,7 +721,7 @@
void Accessors::ScriptEvalFromScriptSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -746,7 +746,7 @@
void Accessors::ScriptEvalFromScriptPositionGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -767,7 +767,7 @@
void Accessors::ScriptEvalFromScriptPositionSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -792,7 +792,7 @@
void Accessors::ScriptEvalFromFunctionNameGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -813,7 +813,7 @@
void Accessors::ScriptEvalFromFunctionNameSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
@@ -884,7 +884,7 @@
void Accessors::FunctionPrototypeGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -896,7 +896,7 @@
void Accessors::FunctionPrototypeSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
@@ -927,7 +927,7 @@
void Accessors::FunctionLengthGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -953,7 +953,7 @@
void Accessors::FunctionLengthSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
// Function length is non writable, non configurable.
@@ -977,7 +977,7 @@
void Accessors::FunctionNameGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -989,7 +989,7 @@
void Accessors::FunctionNameSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
// Function name is non writable, non configurable.
@@ -1114,7 +1114,7 @@
void Accessors::FunctionArgumentsGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -1126,7 +1126,7 @@
void Accessors::FunctionArgumentsSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
// Function arguments is non writable, non configurable.
@@ -1257,7 +1257,7 @@
void Accessors::FunctionCallerGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -1277,7 +1277,7 @@
void Accessors::FunctionCallerSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
// Function caller is non writable, non configurable.
=======================================
--- /branches/bleeding_edge/src/accessors.h Mon Aug 11 12:57:25 2014 UTC
+++ /branches/bleeding_edge/src/accessors.h Wed Aug 20 15:25:13 2014 UTC
@@ -43,10 +43,10 @@
// Accessor descriptors.
#define ACCESSOR_INFO_DECLARATION(name) \
static void name##Getter( \
- v8::Local<v8::String> name, \
+ v8::Local<v8::Name> name, \
const v8::PropertyCallbackInfo<v8::Value>& info); \
static void name##Setter( \
- v8::Local<v8::String> name, \
+ v8::Local<v8::Name> name, \
v8::Local<v8::Value> value, \
const v8::PropertyCallbackInfo<void>& info); \
static Handle<AccessorInfo> name##Info( \
@@ -83,9 +83,9 @@
static Handle<AccessorInfo> MakeAccessor(
Isolate* isolate,
- Handle<String> name,
- AccessorGetterCallback getter,
- AccessorSetterCallback setter,
+ Handle<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback setter,
PropertyAttributes attributes);
static Handle<ExecutableAccessorInfo> CloneAccessor(
=======================================
--- /branches/bleeding_edge/src/api.cc Wed Aug 20 14:16:28 2014 UTC
+++ /branches/bleeding_edge/src/api.cc Wed Aug 20 15:25:13 2014 UTC
@@ -828,7 +828,7 @@
}
-void Template::Set(v8::Handle<String> name,
+void Template::Set(v8::Handle<Name> name,
v8::Handle<Data> value,
v8::PropertyAttribute attribute) {
i::Isolate* isolate = i::Isolate::Current();
@@ -845,7 +845,7 @@
void Template::SetAccessorProperty(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<FunctionTemplate> getter,
v8::Local<FunctionTemplate> setter,
v8::PropertyAttribute attribute,
@@ -1156,7 +1156,7 @@
static i::Handle<i::AccessorInfo> SetAccessorInfoProperties(
i::Handle<i::AccessorInfo> obj,
- v8::Handle<String> name,
+ v8::Handle<Name> name,
v8::AccessControl settings,
v8::PropertyAttribute attributes,
v8::Handle<AccessorSignature> signature) {
@@ -1173,7 +1173,7 @@
template<typename Getter, typename Setter>
static i::Handle<i::AccessorInfo> MakeAccessorInfo(
- v8::Handle<String> name,
+ v8::Handle<Name> name,
Getter getter,
Setter setter,
v8::Handle<Value> data,
@@ -1194,7 +1194,7 @@
static i::Handle<i::AccessorInfo> MakeAccessorInfo(
- v8::Handle<String> name,
+ v8::Handle<Name> name,
v8::Handle<v8::DeclaredAccessorDescriptor> descriptor,
void* setter_ignored,
void* data_ignored,
@@ -1345,10 +1345,10 @@
}
-template<typename Setter, typename Getter, typename Data, typename
Template>
+template<typename Getter, typename Setter, typename Data, typename
Template>
static bool TemplateSetAccessor(
Template* template_obj,
- v8::Local<String> name,
+ v8::Local<Name> name,
Getter getter,
Setter setter,
Data data,
@@ -1368,7 +1368,7 @@
bool Template::SetDeclaredAccessor(
- Local<String> name,
+ Local<Name> name,
Local<DeclaredAccessorDescriptor> descriptor,
PropertyAttribute attribute,
Local<AccessorSignature> signature,
@@ -1389,6 +1389,18 @@
TemplateSetAccessor(
this, name, getter, setter, data, settings, attribute, signature);
}
+
+
+void Template::SetNativeDataProperty(v8::Local<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback setter,
+ v8::Handle<Value> data,
+ PropertyAttribute attribute,
+ v8::Local<AccessorSignature>
signature,
+ AccessControl settings) {
+ TemplateSetAccessor(
+ this, name, getter, setter, data, settings, attribute, signature);
+}
void ObjectTemplate::SetAccessor(v8::Handle<String> name,
@@ -1401,6 +1413,18 @@
TemplateSetAccessor(
this, name, getter, setter, data, settings, attribute, signature);
}
+
+
+void ObjectTemplate::SetAccessor(v8::Handle<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback setter,
+ v8::Handle<Value> data,
+ AccessControl settings,
+ PropertyAttribute attribute,
+ v8::Handle<AccessorSignature> signature) {
+ TemplateSetAccessor(
+ this, name, getter, setter, data, settings, attribute, signature);
+}
void ObjectTemplate::SetNamedPropertyHandler(
@@ -2322,6 +2346,11 @@
bool Value::IsFunction() const {
return Utils::OpenHandle(this)->IsJSFunction();
}
+
+
+bool Value::IsName() const {
+ return Utils::OpenHandle(this)->IsName();
+}
bool Value::FullIsString() const {
@@ -2638,6 +2667,14 @@
"v8::Function::Cast()",
"Could not convert to function");
}
+
+
+void v8::Name::CheckCast(v8::Value* that) {
+ i::Handle<i::Object> obj = Utils::OpenHandle(that);
+ Utils::ApiCheck(obj->IsName(),
+ "v8::Name::Cast()",
+ "Could not convert to name");
+}
void v8::String::CheckCast(v8::Value* that) {
@@ -3423,11 +3460,11 @@
}
-template<typename Setter, typename Getter, typename Data>
+template<typename Getter, typename Setter, typename Data>
static inline bool ObjectSetAccessor(Object* obj,
- Handle<String> name,
- Setter getter,
- Getter setter,
+ Handle<Name> name,
+ Getter getter,
+ Setter setter,
Data data,
AccessControl settings,
PropertyAttribute attributes) {
@@ -3462,7 +3499,18 @@
}
-bool Object::SetDeclaredAccessor(Local<String> name,
+bool Object::SetAccessor(Handle<Name> name,
+ AccessorNameGetterCallback getter,
+ AccessorNameSetterCallback setter,
+ v8::Handle<Value> data,
+ AccessControl settings,
+ PropertyAttribute attributes) {
+ return ObjectSetAccessor(
+ this, name, getter, setter, data, settings, attributes);
+}
+
+
+bool Object::SetDeclaredAccessor(Local<Name> name,
Local<DeclaredAccessorDescriptor>
descriptor,
PropertyAttribute attributes,
AccessControl settings) {
@@ -3472,7 +3520,7 @@
}
-void Object::SetAccessorProperty(Local<String> name,
+void Object::SetAccessorProperty(Local<Name> name,
Local<Function> getter,
Handle<Function> setter,
PropertyAttribute attribute,
@@ -7637,9 +7685,9 @@
void InvokeAccessorGetterCallback(
- v8::Local<v8::String> property,
+ v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info,
- v8::AccessorGetterCallback getter) {
+ v8::AccessorNameGetterCallback getter) {
// Leaving JavaScript.
Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
Address getter_address =
reinterpret_cast<Address>(reinterpret_cast<intptr_t>(
=======================================
--- /branches/bleeding_edge/src/api.h Mon Aug 4 11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/api.h Wed Aug 20 15:25:13 2014 UTC
@@ -158,6 +158,7 @@
V(Float32Array, JSTypedArray) \
V(Float64Array, JSTypedArray) \
V(DataView, JSDataView) \
+ V(Name, Name) \
V(String, String) \
V(Symbol, Symbol) \
V(Script, JSFunction) \
@@ -189,6 +190,8 @@
v8::internal::Handle<v8::internal::Object> obj);
static inline Local<Function> ToLocal(
v8::internal::Handle<v8::internal::JSFunction> obj);
+ static inline Local<Name> ToLocal(
+ v8::internal::Handle<v8::internal::Name> obj);
static inline Local<String> ToLocal(
v8::internal::Handle<v8::internal::String> obj);
static inline Local<Symbol> ToLocal(
@@ -333,6 +336,7 @@
MAKE_TO_LOCAL(ToLocal, Context, Context)
MAKE_TO_LOCAL(ToLocal, Object, Value)
MAKE_TO_LOCAL(ToLocal, JSFunction, Function)
+MAKE_TO_LOCAL(ToLocal, Name, Name)
MAKE_TO_LOCAL(ToLocal, String, String)
MAKE_TO_LOCAL(ToLocal, Symbol, Symbol)
MAKE_TO_LOCAL(ToLocal, JSRegExp, RegExp)
@@ -671,9 +675,9 @@
// Interceptor functions called from generated inline caches to notify
// CPU profiler that external callbacks are invoked.
void InvokeAccessorGetterCallback(
- v8::Local<v8::String> property,
+ v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info,
- v8::AccessorGetterCallback getter);
+ v8::AccessorNameGetterCallback getter);
void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&
info,
v8::FunctionCallback callback);
=======================================
--- /branches/bleeding_edge/src/arguments.h Mon Aug 4 11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/arguments.h Wed Aug 20 15:25:13 2014 UTC
@@ -68,13 +68,13 @@
// They are used to generate the Call() functions below
// These aren't included in the list as they have duplicate signatures
// F(NamedPropertyEnumeratorCallback, ...)
-// F(NamedPropertyGetterCallback, ...)
#define FOR_EACH_CALLBACK_TABLE_MAPPING_0(F) \
F(IndexedPropertyEnumeratorCallback, v8::Array) \
#define FOR_EACH_CALLBACK_TABLE_MAPPING_1(F) \
- F(AccessorGetterCallback, v8::Value, v8::Local<v8::String>) \
+ F(NamedPropertyGetterCallback, v8::Value, v8::Local<v8::String>) \
+ F(AccessorNameGetterCallback, v8::Value, v8::Local<v8::Name>) \
F(NamedPropertyQueryCallback, \
v8::Integer, \
v8::Local<v8::String>) \
@@ -102,9 +102,9 @@
v8::Local<v8::Value>) \
#define FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(F) \
- F(AccessorSetterCallback, \
+ F(AccessorNameSetterCallback, \
void, \
- v8::Local<v8::String>, \
+ v8::Local<v8::Name>, \
v8::Local<v8::Value>) \
=======================================
--- /branches/bleeding_edge/src/arm64/simulator-arm64.cc Mon Aug 4
12:46:43 2014 UTC
+++ /branches/bleeding_edge/src/arm64/simulator-arm64.cc Wed Aug 20
15:25:13 2014 UTC
@@ -704,7 +704,7 @@
case ExternalReference::PROFILING_GETTER_CALL: {
// void f(Local<String> property, PropertyCallbackInfo& info,
- // AccessorGetterCallback callback)
+ // AccessorNameGetterCallback callback)
TraceSim("Type: PROFILING_GETTER_CALL\n");
SimulatorRuntimeProfilingGetterCall target =
reinterpret_cast<SimulatorRuntimeProfilingGetterCall>(
=======================================
--- /branches/bleeding_edge/src/assembler.h Wed Aug 6 07:20:14 2014 UTC
+++ /branches/bleeding_edge/src/assembler.h Wed Aug 20 15:25:13 2014 UTC
@@ -774,12 +774,12 @@
PROFILING_API_CALL,
// Direct call to accessor getter callback.
- // void f(Local<String> property, PropertyCallbackInfo& info)
+ // void f(Local<Name> property, PropertyCallbackInfo& info)
DIRECT_GETTER_CALL,
// Call to accessor getter callback via InvokeAccessorGetterCallback.
- // void f(Local<String> property, PropertyCallbackInfo& info,
- // AccessorGetterCallback callback)
+ // void f(Local<Name> property, PropertyCallbackInfo& info,
+ // AccessorNameGetterCallback callback)
PROFILING_GETTER_CALL
};
=======================================
--- /branches/bleeding_edge/src/objects.cc Wed Aug 20 10:37:23 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc Wed Aug 20 15:25:13 2014 UTC
@@ -428,9 +428,6 @@
ARRAY_SIZE(args)));
return isolate->Throw<Object>(error);
}
- // TODO(rossberg): Handling symbols in the API requires changing the
API,
- // so we do not support it for now.
- if (name->IsSymbol()) return isolate->factory()->undefined_value();
if (structure->IsDeclaredAccessorInfo()) {
return GetDeclaredAccessorProperty(
receiver,
@@ -440,15 +437,14 @@
Handle<ExecutableAccessorInfo> data =
Handle<ExecutableAccessorInfo>::cast(structure);
- v8::AccessorGetterCallback call_fun =
- v8::ToCData<v8::AccessorGetterCallback>(data->getter());
+ v8::AccessorNameGetterCallback call_fun =
+ v8::ToCData<v8::AccessorNameGetterCallback>(data->getter());
if (call_fun == NULL) return isolate->factory()->undefined_value();
- Handle<String> key = Handle<String>::cast(name);
LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name));
PropertyCallbackArguments args(isolate, data->data(), *receiver,
*holder);
v8::Handle<v8::Value> result =
- args.Call(call_fun, v8::Utils::ToLocal(key));
+ args.Call(call_fun, v8::Utils::ToLocal(name));
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
if (result.IsEmpty()) {
return isolate->factory()->undefined_value();
@@ -504,17 +500,14 @@
ARRAY_SIZE(args)));
return isolate->Throw<Object>(error);
}
- // TODO(rossberg): Support symbols in the API.
- if (name->IsSymbol()) return value;
Object* call_obj = info->setter();
- v8::AccessorSetterCallback call_fun =
- v8::ToCData<v8::AccessorSetterCallback>(call_obj);
+ v8::AccessorNameSetterCallback call_fun =
+ v8::ToCData<v8::AccessorNameSetterCallback>(call_obj);
if (call_fun == NULL) return value;
- Handle<String> key = Handle<String>::cast(name);
LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name));
PropertyCallbackArguments args(isolate, info->data(), *receiver,
*holder);
args.Call(call_fun,
- v8::Utils::ToLocal(key),
+ v8::Utils::ToLocal(name),
v8::Utils::ToLocal(value));
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
return value;
@@ -11959,8 +11952,8 @@
Handle<ExecutableAccessorInfo> data =
Handle<ExecutableAccessorInfo>::cast(structure);
Object* fun_obj = data->getter();
- v8::AccessorGetterCallback call_fun =
- v8::ToCData<v8::AccessorGetterCallback>(fun_obj);
+ v8::AccessorNameGetterCallback call_fun =
+ v8::ToCData<v8::AccessorNameGetterCallback>(fun_obj);
if (call_fun == NULL) return isolate->factory()->undefined_value();
Handle<JSObject> holder_handle = Handle<JSObject>::cast(holder);
Handle<Object> number = isolate->factory()->NewNumberFromUint(index);
@@ -12017,8 +12010,8 @@
Handle<ExecutableAccessorInfo> data =
Handle<ExecutableAccessorInfo>::cast(structure);
Object* call_obj = data->setter();
- v8::AccessorSetterCallback call_fun =
- v8::ToCData<v8::AccessorSetterCallback>(call_obj);
+ v8::AccessorNameSetterCallback call_fun =
+ v8::ToCData<v8::AccessorNameSetterCallback>(call_obj);
if (call_fun == NULL) return value;
Handle<Object> number = isolate->factory()->NewNumberFromUint(index);
Handle<String> key(isolate->factory()->NumberToString(number));
=======================================
--- /branches/bleeding_edge/src/stub-cache.cc Tue Aug 19 17:02:04 2014 UTC
+++ /branches/bleeding_edge/src/stub-cache.cc Wed Aug 20 15:25:13 2014 UTC
@@ -503,18 +503,14 @@
DCHECK(callback->IsCompatibleReceiver(*receiver));
Address setter_address = v8::ToCData<Address>(callback->setter());
- v8::AccessorSetterCallback fun =
- FUNCTION_CAST<v8::AccessorSetterCallback>(setter_address);
+ v8::AccessorNameSetterCallback fun =
+ FUNCTION_CAST<v8::AccessorNameSetterCallback>(setter_address);
DCHECK(fun != NULL);
- // TODO(rossberg): Support symbols in the API.
- if (name->IsSymbol()) return *value;
- Handle<String> str = Handle<String>::cast(name);
-
LOG(isolate, ApiNamedPropertyAccess("store", *receiver, *name));
PropertyCallbackArguments custom_args(isolate, callback->data(),
*receiver,
*holder);
- custom_args.Call(fun, v8::Utils::ToLocal(str),
v8::Utils::ToLocal(value));
+ custom_args.Call(fun, v8::Utils::ToLocal(name),
v8::Utils::ToLocal(value));
RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
return *value;
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-alloc.cc Mon Aug 4 11:34:54
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-alloc.cc Wed Aug 20 15:25:13
2014 UTC
@@ -106,7 +106,7 @@
void TestGetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
@@ -115,7 +115,7 @@
void TestSetter(
- v8::Local<v8::String> name,
+ v8::Local<v8::Name> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Wed Aug 20 10:37:23
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-api.cc Wed Aug 20 15:25:13
2014 UTC
@@ -63,6 +63,7 @@
using ::v8::Handle;
using ::v8::HandleScope;
using ::v8::Local;
+using ::v8::Name;
using ::v8::Message;
using ::v8::MessageCallback;
using ::v8::Object;
@@ -71,6 +72,7 @@
using ::v8::Script;
using ::v8::StackTrace;
using ::v8::String;
+using ::v8::Symbol;
using ::v8::TryCatch;
using ::v8::Undefined;
using ::v8::UniqueId;
@@ -1890,6 +1892,24 @@
Handle<Object> self = Handle<Object>::Cast(info.This());
self->Set(String::Concat(v8_str("accessor_"), name), value);
}
+
+void SymbolAccessorGetter(Local<Name> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info)
{
+ CHECK(name->IsSymbol());
+ Local<Symbol> sym = Local<Symbol>::Cast(name);
+ if (sym->Name()->IsUndefined())
+ return;
+ SimpleAccessorGetter(Local<String>::Cast(sym->Name()), info);
+}
+
+void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
+ const v8::PropertyCallbackInfo<void>& info) {
+ CHECK(name->IsSymbol());
+ Local<Symbol> sym = Local<Symbol>::Cast(name);
+ if (sym->Name()->IsUndefined())
+ return;
+ SimpleAccessorSetter(Local<String>::Cast(sym->Name()), value, info);
+}
void EmptyInterceptorGetter(Local<String> name,
const v8::PropertyCallbackInfo<v8::Value>&
info) {
@@ -1947,6 +1967,14 @@
v8::NamedPropertySetterCallback setter) {
templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
}
+
+
+void AddAccessor(Handle<FunctionTemplate> templ,
+ Handle<Name> name,
+ v8::AccessorNameGetterCallback getter,
+ v8::AccessorNameSetterCallback setter) {
+ templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
+}
THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) {
@@ -2759,6 +2787,8 @@
v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
v8::Local<v8::Symbol> sym2 =
v8::Symbol::New(isolate, v8_str("my-symbol"));
+ v8::Local<v8::Symbol> sym3 =
+ v8::Symbol::New(isolate, v8_str("sym3"));
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
@@ -2814,27 +2844,44 @@
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
+ CHECK(obj->SetAccessor(sym3, SymbolAccessorGetter,
SymbolAccessorSetter));
+ CHECK(obj->Get(sym3)->IsUndefined());
+ CHECK(obj->Set(sym3, v8::Integer::New(isolate, 42)));
+ CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42)));
+
CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3"))->Equals(
+ v8::Integer::New(isolate, 42)));
+
// Add another property and delete it afterwards to force the object in
// slow case.
CHECK(obj->Set(sym2, v8::Integer::New(isolate, 2008)));
CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
CHECK_EQ(2008, obj->Get(sym2)->Int32Value());
CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
- CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
+ CHECK_EQ(2, obj->GetOwnPropertyNames()->Length());
CHECK(obj->Has(sym1));
CHECK(obj->Has(sym2));
+ CHECK(obj->Has(sym3));
+ CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3")));
CHECK(obj->Delete(sym2));
CHECK(obj->Has(sym1));
CHECK(!obj->Has(sym2));
+ CHECK(obj->Has(sym3));
+ CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3")));
CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
- CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
+ CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42)));
+
CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3"))->Equals(
+ v8::Integer::New(isolate, 42)));
+ CHECK_EQ(2, obj->GetOwnPropertyNames()->Length());
// Symbol properties are inherited.
v8::Local<v8::Object> child = v8::Object::New(isolate);
child->SetPrototype(obj);
CHECK(child->Has(sym1));
CHECK_EQ(2002, child->Get(sym1)->Int32Value());
+ CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42)));
+
CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3"))->Equals(
+ v8::Integer::New(isolate, 42)));
CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.