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

Unified Diff: src/property-descriptor.cc

Issue 1408163005: [es6] Partially implement Reflect.getOwnPropertyDescriptor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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
Index: src/property-descriptor.cc
diff --git a/src/property-descriptor.cc b/src/property-descriptor.cc
index 2ecf75a74e593f37587ffb337d81bbe4e8b3dd68..53d6e61f2b89b5f1c486a448e636a02a23602498 100644
--- a/src/property-descriptor.cc
+++ b/src/property-descriptor.cc
@@ -101,6 +101,46 @@ bool ToPropertyDescriptorFastPath(Isolate* isolate, Handle<Object> obj,
}
+static void CreateDataProperty(Isolate* isolate, Handle<JSObject> object,
+ const char* name, Handle<Object> value) {
+ LookupIterator it(object,
+ isolate->factory()->NewStringFromAsciiChecked(name));
+ Maybe<bool> result = JSObject::CreateDataProperty(&it, value);
+ CHECK(result.IsJust() && result.FromJust());
+}
+
+
+// ES6 6.2.4.4 "FromPropertyDescriptor"
+// We restrict ourselves to the case where the descriptor is either a complete
+// accessor descriptor or a complete data descriptor, as is true for the result
+// of JSReceiver::GetOwnPropertyDescriptor.
+Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) {
+ DCHECK(PropertyDescriptor::IsAccessorDescriptor(this) !=
+ PropertyDescriptor::IsDataDescriptor(this));
+ Handle<JSObject> result =
+ isolate->factory()->NewJSObject(isolate->object_function());
+ if (PropertyDescriptor::IsAccessorDescriptor(this)) {
+ DCHECK(has_get());
+ CreateDataProperty(isolate, result, "get", get());
Jakob Kummerow 2015/10/26 13:58:26 I'm a bit concerned about the speed of building ob
+ DCHECK(has_set());
+ CreateDataProperty(isolate, result, "set", set());
+ } else {
+ DCHECK(has_value());
+ CreateDataProperty(isolate, result, "value", value());
+ DCHECK(has_writable());
+ CreateDataProperty(isolate, result, "writable",
+ isolate->factory()->ToBoolean(writable()));
+ }
+ DCHECK(has_enumerable());
+ CreateDataProperty(isolate, result, "enumerable",
+ isolate->factory()->ToBoolean(enumerable()));
+ DCHECK(has_configurable());
+ CreateDataProperty(isolate, result, "configurable",
+ isolate->factory()->ToBoolean(configurable()));
+ return result;
+}
+
+
// ES6 6.2.4.5
// Returns false in case of exception.
// static

Powered by Google App Engine
This is Rietveld 408576698