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

Unified Diff: src/accessors.cc

Issue 993073002: [es6] Function length property should be configurable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix status file again Created 5 years, 9 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/bootstrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index 51fdee67f28e5b0cd0ca0070842e5124de7fb2a1..f774c6db467e900e3c382094ecacf1b6a8ca0ed8 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -1095,12 +1095,52 @@ void Accessors::FunctionLengthGetter(
}
+MUST_USE_RESULT static MaybeHandle<Object> ReplaceAccessorWithDataProperty(
+ Isolate* isolate, Handle<JSObject> object, Handle<Name> name,
+ Handle<Object> value, bool is_observed, Handle<Object> old_value) {
+ LookupIterator it(object, name);
+ CHECK_EQ(LookupIterator::ACCESSOR, it.state());
+ DCHECK(it.HolderIsReceiverOrHiddenPrototype());
+ it.ReconfigureDataProperty(value, it.property_details().attributes());
+ value = it.WriteDataValue(value);
+
+ if (is_observed && !old_value->SameValue(*value)) {
+ return JSObject::EnqueueChangeRecord(object, "update", name, old_value);
+ }
+
+ return value;
+}
+
+
+MUST_USE_RESULT static MaybeHandle<Object> SetFunctionLength(
+ Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) {
+ Handle<Object> old_value;
+ bool is_observed = function->map()->is_observed();
+ if (is_observed) {
+ old_value = handle(Smi::FromInt(function->shared()->length()), isolate);
+ }
+
+ return ReplaceAccessorWithDataProperty(isolate, function,
+ isolate->factory()->length_string(),
+ value, is_observed, old_value);
+}
+
+
void Accessors::FunctionLengthSetter(
v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
- // Function length is non writable, non configurable.
- UNREACHABLE();
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
+ HandleScope scope(isolate);
+ Handle<Object> value = Utils::OpenHandle(*val);
+
+ if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return;
+
+ Handle<JSFunction> object =
+ Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
+ if (SetFunctionLength(isolate, object, value).is_null()) {
+ isolate->OptionalRescheduleException(false);
+ }
}
@@ -1139,18 +1179,9 @@ MUST_USE_RESULT static MaybeHandle<Object> SetFunctionName(
old_value = handle(function->shared()->name(), isolate);
}
- Handle<Name> name = isolate->factory()->name_string();
- LookupIterator it(function, name);
- CHECK_EQ(LookupIterator::ACCESSOR, it.state());
- DCHECK(it.HolderIsReceiverOrHiddenPrototype());
- it.ReconfigureDataProperty(value, it.property_details().attributes());
- value = it.WriteDataValue(value);
-
- if (is_observed && !old_value->SameValue(*value)) {
- return JSObject::EnqueueChangeRecord(function, "update", name, old_value);
- }
-
- return value;
+ return ReplaceAccessorWithDataProperty(isolate, function,
+ isolate->factory()->name_string(),
+ value, is_observed, old_value);
}
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698