Chromium Code Reviews| Index: src/builtins.cc |
| diff --git a/src/builtins.cc b/src/builtins.cc |
| index 3530b59def0323b2930d547331c7cca76135e2fc..d8a434f43b4b319d5f26bfaaf354e3c43c21c503 100644 |
| --- a/src/builtins.cc |
| +++ b/src/builtins.cc |
| @@ -17,6 +17,7 @@ |
| #include "src/isolate-inl.h" |
| #include "src/messages.h" |
| #include "src/profiler/cpu-profiler.h" |
| +#include "src/property-descriptor.h" |
| #include "src/prototype.h" |
| #include "src/vm-state-inl.h" |
| @@ -1444,6 +1445,38 @@ BUILTIN(ArrayConcat) { |
| } |
| +// ES6 section 26.1.3 Reflect.defineProperty |
| +BUILTIN(ReflectDefineProperty) { |
| + HandleScope scope(isolate); |
| + DCHECK_EQ(4, args.length()); |
| + Handle<Object> target = args.at<Object>(1); |
| + Handle<Object> key = args.at<Object>(2); |
| + Handle<Object> attributes = args.at<Object>(3); |
| + |
|
Jakob Kummerow
2015/10/23 12:03:42
Suggestion: add verbatim spec steps as comments, e
|
| + if (!target->IsJSReceiver()) { |
| + THROW_NEW_ERROR_RETURN_FAILURE( |
| + isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| + isolate->factory()->NewStringFromAsciiChecked( |
| + "Reflect.defineProperty"))); |
| + } |
| + |
| + Handle<Name> name; |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| + Object::ToName(isolate, key)); |
|
Jakob Kummerow
2015/10/23 12:03:42
Using ToPropertyKey (currently a static function i
neis
2015/10/29 15:17:25
Thanks, good point. I'll do that in a separate CL
|
| + |
| + PropertyDescriptor desc; |
| + if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { |
| + return isolate->heap()->exception(); |
| + } |
| + |
| + bool result = JSReceiver::DefineOwnProperty( |
| + isolate, Handle<JSReceiver>::cast(target), name, &desc, DONT_THROW); |
| + if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
| + // TODO(neis): Make DefineOwnProperty return Maybe<bool>. |
| + return *isolate->factory()->ToBoolean(result); |
| +} |
| + |
| + |
| // ES6 section 26.1.4 Reflect.deleteProperty |
| BUILTIN(ReflectDeleteProperty) { |
| HandleScope scope(isolate); |