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

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: Move destructor. 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 fa572b0a00e2d9f1517ef5fd4448c547453657c3..4b834ebe72062dae1e377edd312df81fbface829 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -96,6 +96,7 @@ class ObjectTemplate;
class Platform;
class Primitive;
class Promise;
+class PropertyDescriptor;
class Proxy;
class RawOperationDescriptor;
class Script;
@@ -2791,6 +2792,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.
//
@@ -3608,6 +3624,61 @@ 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.
+ *
+ * Accessors `get` or `set` must be callable, unless they are undefined. Use
+ * empty handles to indicate that `value`, `get`, or `set` are not set.
+ *
+ * \code
+ * PropertyDescriptor(Local<Function>())) // var desc = {}
+ * PropertyDescriptor(v8::Undefined(isolate)) // var desc = {get: undefined}
+ * \endcode
+ */
+class V8_EXPORT PropertyDescriptor {
+ public:
+ enum State { kTrue = 0, kFalse = 1, kNotSet = 2 };
+
+ // GenericDescriptor
+ PropertyDescriptor();
+
+ // DataDescriptor
+ PropertyDescriptor(Local<Value> value, State writable);
+
+ // AccessorDescriptor
+ PropertyDescriptor(Local<Value> get, Local<Value> set);
+
+ ~PropertyDescriptor();
+
+ Local<Value> value() const;
+ bool has_value() const;
+
+ Local<Value> get() const;
+ bool has_get() const;
+ Local<Value> set() const;
+ bool has_set() const;
+
+ void set_enumerable(bool enumerable);
+ State enumerable() const;
Jakob Kummerow 2016/08/29 12:32:23 I'd be fine with a "bool enumerable() / bool has_e
Franzi 2016/08/31 09:44:13 As discussed, I'm using bool instead of the enum S
+
+ void set_configurable(bool configurable);
+ State configurable() const;
+
+ State writable() const;
+
+ PropertyDescriptor(const PropertyDescriptor&) = delete;
+ void operator=(const PropertyDescriptor&) = delete;
+
+ private:
+ struct PrivateData;
+ PrivateData* private_;
+};
/**
* 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