diff options
Diffstat (limited to 'deps/v8/src/accessors.cc')
-rw-r--r-- | deps/v8/src/accessors.cc | 97 |
1 files changed, 71 insertions, 26 deletions
diff --git a/deps/v8/src/accessors.cc b/deps/v8/src/accessors.cc index e08f86fc22..f774c6db46 100644 --- a/deps/v8/src/accessors.cc +++ b/deps/v8/src/accessors.cc @@ -242,14 +242,8 @@ void Accessors::ArrayLengthSetter( return; } - Handle<Object> exception; - maybe = isolate->factory()->NewRangeError("invalid_array_length", - HandleVector<Object>(NULL, 0)); - if (!maybe.ToHandle(&exception)) { - isolate->OptionalRescheduleException(false); - return; - } - + Handle<Object> exception = isolate->factory()->NewRangeError( + "invalid_array_length", HandleVector<Object>(NULL, 0)); isolate->ScheduleThrow(*exception); } @@ -1101,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); + } } @@ -1137,12 +1171,35 @@ void Accessors::FunctionNameGetter( } +MUST_USE_RESULT static MaybeHandle<Object> SetFunctionName( + 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(function->shared()->name(), isolate); + } + + return ReplaceAccessorWithDataProperty(isolate, function, + isolate->factory()->name_string(), + value, is_observed, old_value); +} + + void Accessors::FunctionNameSetter( v8::Local<v8::Name> name, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info) { - // Function name 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 (SetFunctionName(isolate, object, value).is_null()) { + isolate->OptionalRescheduleException(false); + } } @@ -1459,14 +1516,8 @@ static void ModuleGetExport( if (value->IsTheHole()) { Handle<String> name = v8::Utils::OpenHandle(*property); - Handle<Object> exception; - MaybeHandle<Object> maybe = isolate->factory()->NewReferenceError( + Handle<Object> exception = isolate->factory()->NewReferenceError( "not_defined", HandleVector(&name, 1)); - if (!maybe.ToHandle(&exception)) { - isolate->OptionalRescheduleException(false); - return; - } - isolate->ScheduleThrow(*exception); return; } @@ -1486,14 +1537,8 @@ static void ModuleSetExport( Isolate* isolate = context->GetIsolate(); if (old_value->IsTheHole()) { Handle<String> name = v8::Utils::OpenHandle(*property); - Handle<Object> exception; - MaybeHandle<Object> maybe = isolate->factory()->NewReferenceError( + Handle<Object> exception = isolate->factory()->NewReferenceError( "not_defined", HandleVector(&name, 1)); - if (!maybe.ToHandle(&exception)) { - isolate->OptionalRescheduleException(false); - return; - } - isolate->ScheduleThrow(*exception); return; } |