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

Unified Diff: include/v8.h

Issue 2244123005: [api] Add PropertyDescriptor and DefineProperty(). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Reword comment. Created 4 years, 4 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.cc » ('j') | src/api.cc » ('J')
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 34fba61527952620b10a63f9e706658617c10f77..a25e2f715aa5bd410ea341d1757276fe49283681 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;
@@ -2695,6 +2696,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), see Ecma-262 19.1.2.4.
+ //
+ // The defineProperty function is used to add an own property or
+ // update the attributes of an existing own property of an object.
+ //
+ // Both data and accessor descriptors can be used.
+ //
+ // In general, CreateDataProperty is faster, however, does not allow
+ // 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);
+
// Sets an own property on this object bypassing interceptors and
// overriding accessors or read-only properties.
//
@@ -3433,6 +3449,88 @@ class V8_EXPORT Promise : public Object {
static void CheckCast(Value* obj);
};
+/**
+ * An instance of a Property Descriptor, see Ecma-262 6.2.4.
+ *
+ * This property descriptor is immutable except for its properties enumerable
+ * and configurable. An invalid descriptor that is both
+ * a data and accessor descriptor can not be generated. To determine if
+ * a descriptor is an accessor, data, or generic descriptor, use the
+ * `has_x()` functions for appropriate x.
+ *
+ * Empty handles for `get` or `set` are interpreted as undefined.
Jakob Kummerow 2016/08/26 13:28:30 Is there a particular reason for this, which cause
+ *
+ * The difference between `hax_x() = false` and setting x to undefined or empty
+ * handle is important when re-defining a property. When re-defining,
+ * `has_x() = false`
+ * does not cause a type error if x is already defined differently.
+ * \code
+ * PropertyDescriptor(Local<Function>()), true) // var desc = {get: undefined}
+ * PropertyDescriptor() // var desc = {}
+ * \endcode
+ */
+class V8_EXPORT PropertyDescriptor {
+ public:
+ // GenericDescriptor
+ PropertyDescriptor() {}
+
+ // DataDescriptor
+ PropertyDescriptor(Local<Value> value, bool has_value, bool writable,
+ bool has_writable)
+ : value_(value),
+ has_value_(has_value),
+ writable_(writable),
+ has_writable_(has_writable) {}
+
+ // AccessorDescriptor
+ PropertyDescriptor(Local<Function> get, bool has_get, Local<Function> set,
+ bool has_set)
+ : get_(get), has_get_(has_get), set_(set), has_set_(has_set) {}
+
+ 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_; }
+
+ void set_enumerable(bool enumeralbe) {
Jakob Kummerow 2016/08/26 13:28:30 nit: typo
Franzi 2016/08/31 09:44:13 Done.
+ enumerable_ = enumeralbe;
+ has_enumerable_ = true;
+ }
+ bool enumerable() const { return enumerable_; }
+ bool has_enumerable() const { return has_enumerable_; }
+
+ void set_configurable(bool configurable) {
+ configurable_ = configurable;
+ has_configurable_ = true;
+ }
+ bool configurable() const { return configurable_; }
+ bool has_configurable() const { return has_configurable_; }
+
+ bool writable() const { return writable_; }
+ bool has_writable() const { return has_writable_; }
+
+ PropertyDescriptor(const PropertyDescriptor&) = delete;
+ void operator=(const PropertyDescriptor&) = delete;
+
+ 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,
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698