Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index 10b563c83aad2b700e4dd991f9862808c68ce3b5..1f2f29dc19a2da7d34b33510bbc06ff61b9e4e64 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -95,6 +95,7 @@ class ObjectTemplate; |
class Platform; |
class Primitive; |
class Promise; |
+class PropertyDescriptor; |
class Proxy; |
class RawOperationDescriptor; |
class Script; |
@@ -2693,6 +2694,21 @@ class V8_EXPORT Object : public Value { |
Local<Context> context, Local<Name> key, Local<Value> value, |
PropertyAttribute attributes = None); |
+ // Implements Object.DefineProperty(O, P, Attributes) as in ecma262 19.1.2.4. |
+ // |
+ // The defineProperty function is used to add an own property and/or |
Toon Verwaest
2016/08/18 07:25:39
or. You can't add 'add' and 'update' a property :)
Franzi
2016/08/18 09:56:24
Done.
|
+ // update the attributes of an existing own property of an object. |
+ // |
+ // Both data and accessor descriptors can be used. |
+ // |
+ // In general, CreateDataProperty will be faster, however, does not allow |
Toon Verwaest
2016/08/18 07:25:39
is faster
Franzi
2016/08/18 09:56:24
Done.
|
+ // for specifying attributes or an accessor descriptor. |
+ // |
+ // Returns true on success. |
+ V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty( |
+ Local<Context> context, Local<Name> key, |
+ const PropertyDescriptor* descriptor); |
Toon Verwaest
2016/08/18 07:25:39
Perhaps this should be a reference? We'll probably
Franzi
2016/08/18 09:56:24
Done.
|
+ |
// Sets an own property on this object bypassing interceptors and |
// overriding accessors or read-only properties. |
// |
@@ -3437,6 +3453,79 @@ class V8_EXPORT Promise : public Object { |
static void CheckCast(Value* obj); |
}; |
+/** |
+ * Property Descriptor. |
+ */ |
+class V8_EXPORT PropertyDescriptor { |
+ public: |
+ // GenericDescriptor |
+ PropertyDescriptor(bool enumerable = false, bool has_enumerable = false, |
+ bool configurable = false, bool has_configurable = false) |
+ : enumerable_(enumerable), |
+ has_enumerable_(has_enumerable), |
+ configurable_(configurable), |
+ has_configurable_(has_configurable) {} |
+ |
+ // DataDescriptor |
+ PropertyDescriptor(Local<Value> value, bool has_value, |
+ bool enumerable = false, bool has_enumerable = false, |
+ bool configurable = false, bool has_configurable = false, |
+ bool writable = false, bool has_writable = false) |
+ : value_(value), |
+ has_value_(has_value), |
+ enumerable_(enumerable), |
+ has_enumerable_(has_enumerable), |
+ configurable_(configurable), |
+ has_configurable_(has_configurable), |
+ writable_(writable), |
+ has_writable_(has_writable) {} |
+ |
+ // AccessorDescriptor |
+ PropertyDescriptor(Local<Function> get, bool has_get = false, |
Toon Verwaest
2016/08/18 07:25:39
If we can get by without has_get etc, I'd prefer t
Franzi
2016/08/18 09:56:24
We need has_x() for all fields. We need to disting
|
+ Local<Function> set = Local<Function>(), |
+ bool has_set = false, bool enumerable = false, |
+ bool has_enumerable = false, bool configurable = false, |
+ bool has_configurable = false) |
+ : get_(get), |
+ has_get_(has_get), |
+ set_(set), |
+ has_set_(has_set), |
+ enumerable_(enumerable), |
+ has_enumerable_(has_enumerable), |
+ configurable_(configurable), |
+ has_configurable_(has_configurable) {} |
+ |
+ Local<Value> value() const { return value_; } |
+ bool has_value() const { return has_value_; } |
+ |
+ Local<Function> get() const { return get_; } |
+ bool has_get() const { return has_get_; } |
+ Local<Function> set() const { return set_; } |
+ bool has_set() const { return has_set_; } |
+ |
+ bool enumerable() const { return enumerable_; } |
+ bool has_enumerable() const { return has_enumerable_; } |
+ bool configurable() const { return configurable_; } |
+ bool has_configurable() const { return has_configurable_; } |
+ bool writable() const { return writable_; } |
+ bool has_writable() const { return has_writable_; } |
+ |
+ private: |
+ Local<Value> value_; |
+ bool has_value_ = false; |
+ |
+ Local<Function> get_; |
+ bool has_get_ = false; |
+ Local<Function> set_; |
+ bool has_set_ = false; |
+ |
+ bool enumerable_ = false; |
+ bool has_enumerable_ = false; |
+ bool configurable_ = false; |
+ bool has_configurable_ = false; |
+ bool writable_ = false; |
+ bool has_writable_ = false; |
+}; |
/** |
* An instance of the built-in Proxy constructor (ECMA-262, 6th Edition, |