summaryrefslogtreecommitdiff
path: root/deps/v8/src/accessors.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/accessors.cc')
-rw-r--r--deps/v8/src/accessors.cc520
1 files changed, 132 insertions, 388 deletions
diff --git a/deps/v8/src/accessors.cc b/deps/v8/src/accessors.cc
index 2094cdb20d..766509e2a5 100644
--- a/deps/v8/src/accessors.cc
+++ b/deps/v8/src/accessors.cc
@@ -27,13 +27,15 @@ Handle<AccessorInfo> Accessors::MakeAccessor(
AccessorNameSetterCallback setter,
PropertyAttributes attributes) {
Factory* factory = isolate->factory();
- Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
+ Handle<AccessorInfo> info = factory->NewAccessorInfo();
info->set_property_attributes(attributes);
info->set_all_can_read(false);
info->set_all_can_write(false);
info->set_is_special_data_property(true);
+ name = factory->InternalizeName(name);
info->set_name(*name);
Handle<Object> get = v8::FromCData(isolate, getter);
+ if (setter == nullptr) setter = &ReconfigureToDataProperty;
Handle<Object> set = v8::FromCData(isolate, setter);
info->set_getter(*get);
info->set_setter(*set);
@@ -41,21 +43,6 @@ Handle<AccessorInfo> Accessors::MakeAccessor(
}
-Handle<ExecutableAccessorInfo> Accessors::CloneAccessor(
- Isolate* isolate,
- Handle<ExecutableAccessorInfo> accessor) {
- Factory* factory = isolate->factory();
- Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
- info->set_name(accessor->name());
- info->set_flag(accessor->flag());
- info->set_expected_receiver_type(accessor->expected_receiver_type());
- info->set_getter(accessor->getter());
- info->set_setter(accessor->setter());
- info->set_data(accessor->data());
- return info;
-}
-
-
static V8_INLINE bool CheckForName(Handle<Name> name,
Handle<String> property_name,
int offset,
@@ -96,6 +83,7 @@ bool Accessors::IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
bool Accessors::IsJSArrayBufferViewFieldAccessor(Handle<Map> map,
Handle<Name> name,
int* object_offset) {
+ DCHECK(name->IsUniqueName());
Isolate* isolate = name->GetIsolate();
switch (map->instance_type()) {
@@ -113,7 +101,7 @@ bool Accessors::IsJSArrayBufferViewFieldAccessor(Handle<Map> map,
// Check if the property is overridden on the instance.
DescriptorArray* descriptors = map->instance_descriptors();
- int descriptor = descriptors->SearchWithCache(*name, *map);
+ int descriptor = descriptors->SearchWithCache(isolate, *name, *map);
if (descriptor != DescriptorArray::kNotFound) return false;
Handle<Object> proto = Handle<Object>(map->prototype(), isolate);
@@ -140,6 +128,50 @@ bool Accessors::IsJSArrayBufferViewFieldAccessor(Handle<Map> map,
}
}
+MUST_USE_RESULT static MaybeHandle<Object> ReplaceAccessorWithDataProperty(
+ Isolate* isolate, Handle<JSObject> receiver, Handle<JSObject> holder,
+ Handle<Name> name, Handle<Object> value, bool observe) {
+ LookupIterator it(receiver, name, holder,
+ LookupIterator::OWN_SKIP_INTERCEPTOR);
+ // Skip any access checks we might hit. This accessor should never hit in a
+ // situation where the caller does not have access.
+ if (it.state() == LookupIterator::ACCESS_CHECK) {
+ CHECK(it.HasAccess());
+ it.Next();
+ }
+ CHECK_EQ(LookupIterator::ACCESSOR, it.state());
+
+ Handle<Object> old_value;
+ bool is_observed = observe && receiver->map()->is_observed();
+ if (is_observed) {
+ MaybeHandle<Object> maybe_old = Object::GetPropertyWithAccessor(&it);
+ if (!maybe_old.ToHandle(&old_value)) return maybe_old;
+ }
+
+ it.ReconfigureDataProperty(value, it.property_attributes());
+
+ if (is_observed && !old_value->SameValue(*value)) {
+ return JSObject::EnqueueChangeRecord(receiver, "update", name, old_value);
+ }
+
+ return value;
+}
+
+void Accessors::ReconfigureToDataProperty(
+ v8::Local<v8::Name> key, v8::Local<v8::Value> val,
+ const v8::PropertyCallbackInfo<void>& info) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
+ HandleScope scope(isolate);
+ Handle<JSObject> receiver =
+ Handle<JSObject>::cast(Utils::OpenHandle(*info.This()));
+ Handle<JSObject> holder =
+ Handle<JSObject>::cast(Utils::OpenHandle(*info.Holder()));
+ Handle<Name> name = Utils::OpenHandle(*key);
+ Handle<Object> value = Utils::OpenHandle(*val);
+ MaybeHandle<Object> result = ReplaceAccessorWithDataProperty(
+ isolate, receiver, holder, name, value, false);
+ if (result.is_null()) isolate->OptionalRescheduleException(false);
+}
//
// Accessors::ArgumentsIterator
@@ -156,29 +188,11 @@ void Accessors::ArgumentsIteratorGetter(
}
-void Accessors::ArgumentsIteratorSetter(
- v8::Local<v8::Name> name, v8::Local<v8::Value> val,
- const v8::PropertyCallbackInfo<void>& info) {
- i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
- HandleScope scope(isolate);
- Handle<JSObject> object_handle =
- Handle<JSObject>::cast(Utils::OpenHandle(*info.This()));
- Handle<Object> value_handle = Utils::OpenHandle(*val);
- Handle<Name> name_handle = Utils::OpenHandle(*name);
-
- if (JSObject::DefinePropertyOrElementIgnoreAttributes(
- object_handle, name_handle, value_handle, NONE)
- .is_null()) {
- isolate->OptionalRescheduleException(false);
- }
-}
-
-
Handle<AccessorInfo> Accessors::ArgumentsIteratorInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<Name> name = isolate->factory()->iterator_symbol();
- return MakeAccessor(isolate, name, &ArgumentsIteratorGetter,
- &ArgumentsIteratorSetter, attributes);
+ return MakeAccessor(isolate, name, &ArgumentsIteratorGetter, nullptr,
+ attributes);
}
@@ -219,6 +233,19 @@ void Accessors::ArrayLengthSetter(
if (JSArray::ObservableSetLength(array, length).is_null()) {
isolate->OptionalRescheduleException(false);
}
+
+ if (info.ShouldThrowOnError()) {
+ uint32_t actual_new_len = 0;
+ CHECK(array->length()->ToArrayLength(&actual_new_len));
+ // Throw TypeError if there were non-deletable elements.
+ if (actual_new_len != length) {
+ Factory* factory = isolate->factory();
+ isolate->Throw(*factory->NewTypeError(
+ MessageTemplate::kStrictDeleteProperty,
+ factory->NewNumberFromUint(actual_new_len - 1), array));
+ isolate->OptionalRescheduleException(false);
+ }
+ }
}
@@ -259,21 +286,10 @@ void Accessors::StringLengthGetter(
}
-void Accessors::StringLengthSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::StringLengthInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->length_string(),
- &StringLengthGetter,
- &StringLengthSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->length_string(),
+ &StringLengthGetter, nullptr, attributes);
}
@@ -295,22 +311,11 @@ void Accessors::ScriptColumnOffsetGetter(
}
-void Accessors::ScriptColumnOffsetSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptColumnOffsetInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("column_offset")));
- return MakeAccessor(isolate,
- name,
- &ScriptColumnOffsetGetter,
- &ScriptColumnOffsetSetter,
+ return MakeAccessor(isolate, name, &ScriptColumnOffsetGetter, nullptr,
attributes);
}
@@ -332,23 +337,11 @@ void Accessors::ScriptIdGetter(
}
-void Accessors::ScriptIdSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptIdInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(
isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("id")));
- return MakeAccessor(isolate,
- name,
- &ScriptIdGetter,
- &ScriptIdSetter,
- attributes);
+ return MakeAccessor(isolate, name, &ScriptIdGetter, nullptr, attributes);
}
@@ -369,21 +362,10 @@ void Accessors::ScriptNameGetter(
}
-void Accessors::ScriptNameSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptNameInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->name_string(),
- &ScriptNameGetter,
- &ScriptNameSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->name_string(),
+ &ScriptNameGetter, nullptr, attributes);
}
@@ -404,21 +386,10 @@ void Accessors::ScriptSourceGetter(
}
-void Accessors::ScriptSourceSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptSourceInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->source_string(),
- &ScriptSourceGetter,
- &ScriptSourceSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->source_string(),
+ &ScriptSourceGetter, nullptr, attributes);
}
@@ -440,22 +411,11 @@ void Accessors::ScriptLineOffsetGetter(
}
-void Accessors::ScriptLineOffsetSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptLineOffsetInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("line_offset")));
- return MakeAccessor(isolate,
- name,
- &ScriptLineOffsetGetter,
- &ScriptLineOffsetSetter,
+ return MakeAccessor(isolate, name, &ScriptLineOffsetGetter, nullptr,
attributes);
}
@@ -478,23 +438,11 @@ void Accessors::ScriptTypeGetter(
}
-void Accessors::ScriptTypeSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptTypeInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(
isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("type")));
- return MakeAccessor(isolate,
- name,
- &ScriptTypeGetter,
- &ScriptTypeSetter,
- attributes);
+ return MakeAccessor(isolate, name, &ScriptTypeGetter, nullptr, attributes);
}
@@ -516,22 +464,11 @@ void Accessors::ScriptCompilationTypeGetter(
}
-void Accessors::ScriptCompilationTypeSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptCompilationTypeInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("compilation_type")));
- return MakeAccessor(isolate,
- name,
- &ScriptCompilationTypeGetter,
- &ScriptCompilationTypeSetter,
+ return MakeAccessor(isolate, name, &ScriptCompilationTypeGetter, nullptr,
attributes);
}
@@ -561,22 +498,11 @@ void Accessors::ScriptLineEndsGetter(
}
-void Accessors::ScriptLineEndsSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptLineEndsInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("line_ends")));
- return MakeAccessor(isolate,
- name,
- &ScriptLineEndsGetter,
- &ScriptLineEndsSetter,
+ return MakeAccessor(isolate, name, &ScriptLineEndsGetter, nullptr,
attributes);
}
@@ -598,21 +524,10 @@ void Accessors::ScriptSourceUrlGetter(
}
-void Accessors::ScriptSourceUrlSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptSourceUrlInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->source_url_string(),
- &ScriptSourceUrlGetter,
- &ScriptSourceUrlSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->source_url_string(),
+ &ScriptSourceUrlGetter, nullptr, attributes);
}
@@ -634,21 +549,10 @@ void Accessors::ScriptSourceMappingUrlGetter(
}
-void Accessors::ScriptSourceMappingUrlSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptSourceMappingUrlInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->source_mapping_url_string(),
- &ScriptSourceMappingUrlGetter,
- &ScriptSourceMappingUrlSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->source_mapping_url_string(),
+ &ScriptSourceMappingUrlGetter, nullptr, attributes);
}
@@ -671,19 +575,12 @@ void Accessors::ScriptIsEmbedderDebugScriptGetter(
}
-void Accessors::ScriptIsEmbedderDebugScriptSetter(
- v8::Local<v8::Name> name, v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptIsEmbedderDebugScriptInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("is_debugger_script")));
return MakeAccessor(isolate, name, &ScriptIsEmbedderDebugScriptGetter,
- &ScriptIsEmbedderDebugScriptSetter, attributes);
+ nullptr, attributes);
}
@@ -704,22 +601,11 @@ void Accessors::ScriptContextDataGetter(
}
-void Accessors::ScriptContextDataSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptContextDataInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("context_data")));
- return MakeAccessor(isolate,
- name,
- &ScriptContextDataGetter,
- &ScriptContextDataSetter,
+ return MakeAccessor(isolate, name, &ScriptContextDataGetter, nullptr,
attributes);
}
@@ -751,22 +637,11 @@ void Accessors::ScriptEvalFromScriptGetter(
}
-void Accessors::ScriptEvalFromScriptSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptEvalFromScriptInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("eval_from_script")));
- return MakeAccessor(isolate,
- name,
- &ScriptEvalFromScriptGetter,
- &ScriptEvalFromScriptSetter,
+ return MakeAccessor(isolate, name, &ScriptEvalFromScriptGetter, nullptr,
attributes);
}
@@ -789,7 +664,6 @@ void Accessors::ScriptEvalFromScriptPositionGetter(
Handle<Code> code(SharedFunctionInfo::cast(
script->eval_from_shared())->code());
result = Handle<Object>(Smi::FromInt(code->SourcePosition(
- code->instruction_start() +
script->eval_from_instructions_offset())),
isolate);
}
@@ -797,23 +671,12 @@ void Accessors::ScriptEvalFromScriptPositionGetter(
}
-void Accessors::ScriptEvalFromScriptPositionSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptEvalFromScriptPositionInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("eval_from_script_position")));
- return MakeAccessor(isolate,
- name,
- &ScriptEvalFromScriptPositionGetter,
- &ScriptEvalFromScriptPositionSetter,
- attributes);
+ return MakeAccessor(isolate, name, &ScriptEvalFromScriptPositionGetter,
+ nullptr, attributes);
}
@@ -843,22 +706,11 @@ void Accessors::ScriptEvalFromFunctionNameGetter(
}
-void Accessors::ScriptEvalFromFunctionNameSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::ScriptEvalFromFunctionNameInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("eval_from_function_name")));
- return MakeAccessor(isolate,
- name,
- &ScriptEvalFromFunctionNameGetter,
- &ScriptEvalFromFunctionNameSetter,
+ return MakeAccessor(isolate, name, &ScriptEvalFromFunctionNameGetter, nullptr,
attributes);
}
@@ -976,59 +828,27 @@ void Accessors::FunctionLengthGetter(
info.GetReturnValue().Set(Utils::ToLocal(result));
}
-
-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());
-
- 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,
+void Accessors::ObservedReconfigureToDataProperty(
+ v8::Local<v8::Name> key, v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
+ Handle<JSObject> receiver =
+ Handle<JSObject>::cast(Utils::OpenHandle(*info.This()));
+ Handle<JSObject> holder =
+ Handle<JSObject>::cast(Utils::OpenHandle(*info.Holder()));
+ Handle<Name> name = Utils::OpenHandle(*key);
Handle<Object> value = Utils::OpenHandle(*val);
-
- Handle<JSFunction> object =
- Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
- if (SetFunctionLength(isolate, object, value).is_null()) {
- isolate->OptionalRescheduleException(false);
- }
+ MaybeHandle<Object> result = ReplaceAccessorWithDataProperty(
+ isolate, receiver, holder, name, value, true);
+ if (result.is_null()) isolate->OptionalRescheduleException(false);
}
Handle<AccessorInfo> Accessors::FunctionLengthInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->length_string(),
- &FunctionLengthGetter,
- &FunctionLengthSetter,
+ return MakeAccessor(isolate, isolate->factory()->length_string(),
+ &FunctionLengthGetter, &ObservedReconfigureToDataProperty,
attributes);
}
@@ -1054,43 +874,10 @@ void Accessors::FunctionNameGetter(
info.GetReturnValue().Set(Utils::ToLocal(result));
}
-
-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) {
- i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
- HandleScope scope(isolate);
- Handle<Object> value = Utils::OpenHandle(*val);
-
- Handle<JSFunction> object =
- Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
- if (SetFunctionName(isolate, object, value).is_null()) {
- isolate->OptionalRescheduleException(false);
- }
-}
-
-
Handle<AccessorInfo> Accessors::FunctionNameInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->name_string(),
- &FunctionNameGetter,
- &FunctionNameSetter,
+ return MakeAccessor(isolate, isolate->factory()->name_string(),
+ &FunctionNameGetter, &ObservedReconfigureToDataProperty,
attributes);
}
@@ -1158,10 +945,10 @@ static int FindFunctionInFrame(JavaScriptFrame* frame,
}
+namespace {
+
Handle<Object> GetFunctionArguments(Isolate* isolate,
Handle<JSFunction> function) {
- if (function->shared()->native()) return isolate->factory()->null_value();
-
// Find the top invocation of the function by traversing frames.
for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
JavaScriptFrame* frame = it.frame();
@@ -1200,9 +987,14 @@ Handle<Object> GetFunctionArguments(Isolate* isolate,
return isolate->factory()->null_value();
}
+} // namespace
-Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
- return GetFunctionArguments(function->GetIsolate(), function);
+
+Handle<JSObject> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
+ Handle<Object> arguments =
+ GetFunctionArguments(function->GetIsolate(), function);
+ CHECK(arguments->IsJSObject());
+ return Handle<JSObject>::cast(arguments);
}
@@ -1213,27 +1005,18 @@ void Accessors::FunctionArgumentsGetter(
HandleScope scope(isolate);
Handle<JSFunction> function =
Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
- Handle<Object> result = GetFunctionArguments(isolate, function);
+ Handle<Object> result =
+ function->shared()->native()
+ ? Handle<Object>::cast(isolate->factory()->null_value())
+ : GetFunctionArguments(isolate, function);
info.GetReturnValue().Set(Utils::ToLocal(result));
}
-void Accessors::FunctionArgumentsSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> val,
- const v8::PropertyCallbackInfo<void>& info) {
- // Function arguments is non writable, non configurable.
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::FunctionArgumentsInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->arguments_string(),
- &FunctionArgumentsGetter,
- &FunctionArgumentsSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->arguments_string(),
+ &FunctionArgumentsGetter, nullptr, attributes);
}
@@ -1363,22 +1146,10 @@ void Accessors::FunctionCallerGetter(
}
-void Accessors::FunctionCallerSetter(
- v8::Local<v8::Name> name,
- v8::Local<v8::Value> val,
- const v8::PropertyCallbackInfo<void>& info) {
- // Function caller is non writable, non configurable.
- UNREACHABLE();
-}
-
-
Handle<AccessorInfo> Accessors::FunctionCallerInfo(
Isolate* isolate, PropertyAttributes attributes) {
- return MakeAccessor(isolate,
- isolate->factory()->caller_string(),
- &FunctionCallerGetter,
- &FunctionCallerSetter,
- attributes);
+ return MakeAccessor(isolate, isolate->factory()->caller_string(),
+ &FunctionCallerGetter, nullptr, attributes);
}
@@ -1386,9 +1157,8 @@ Handle<AccessorInfo> Accessors::FunctionCallerInfo(
// Accessors::MakeModuleExport
//
-static void ModuleGetExport(
- v8::Local<v8::String> property,
- const v8::PropertyCallbackInfo<v8::Value>& info) {
+static void ModuleGetExport(v8::Local<v8::Name> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
Context* context = Context::cast(instance->context());
DCHECK(context->IsModuleContext());
@@ -1397,7 +1167,7 @@ static void ModuleGetExport(
->Int32Value(info.GetIsolate()->GetCurrentContext())
.FromMaybe(-1);
if (slot < 0 || slot >= context->length()) {
- Handle<String> name = v8::Utils::OpenHandle(*property);
+ Handle<Name> name = v8::Utils::OpenHandle(*property);
Handle<Object> exception = isolate->factory()->NewReferenceError(
MessageTemplate::kNotDefined, name);
@@ -1406,7 +1176,7 @@ static void ModuleGetExport(
}
Object* value = context->get(slot);
if (value->IsTheHole()) {
- Handle<String> name = v8::Utils::OpenHandle(*property);
+ Handle<Name> name = v8::Utils::OpenHandle(*property);
Handle<Object> exception = isolate->factory()->NewReferenceError(
MessageTemplate::kNotDefined, name);
@@ -1417,33 +1187,15 @@ static void ModuleGetExport(
}
-static void ModuleSetExport(
- v8::Local<v8::String> property,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<v8::Value>& info) {
- JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
- Context* context = Context::cast(instance->context());
- DCHECK(context->IsModuleContext());
- Isolate* isolate = instance->GetIsolate();
- int slot = info.Data()
- ->Int32Value(info.GetIsolate()->GetCurrentContext())
- .FromMaybe(-1);
- if (slot < 0 || slot >= context->length()) {
- Handle<String> name = v8::Utils::OpenHandle(*property);
- Handle<Object> exception = isolate->factory()->NewReferenceError(
- MessageTemplate::kNotDefined, name);
- isolate->ScheduleThrow(*exception);
- return;
- }
- Object* old_value = context->get(slot);
- if (old_value->IsTheHole()) {
- Handle<String> name = v8::Utils::OpenHandle(*property);
- Handle<Object> exception = isolate->factory()->NewReferenceError(
- MessageTemplate::kNotDefined, name);
- isolate->ScheduleThrow(*exception);
- return;
- }
- context->set(slot, *v8::Utils::OpenHandle(*value));
+static void ModuleSetExport(v8::Local<v8::Name> property,
+ v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info) {
+ if (!info.ShouldThrowOnError()) return;
+ Handle<Name> name = v8::Utils::OpenHandle(*property);
+ Isolate* isolate = name->GetIsolate();
+ Handle<Object> exception =
+ isolate->factory()->NewTypeError(MessageTemplate::kNotDefined, name);
+ isolate->ScheduleThrow(*exception);
}
@@ -1452,17 +1204,9 @@ Handle<AccessorInfo> Accessors::MakeModuleExport(
int index,
PropertyAttributes attributes) {
Isolate* isolate = name->GetIsolate();
- Factory* factory = isolate->factory();
- Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
- info->set_property_attributes(attributes);
- info->set_all_can_read(true);
- info->set_all_can_write(true);
- info->set_name(*name);
+ Handle<AccessorInfo> info = MakeAccessor(isolate, name, &ModuleGetExport,
+ &ModuleSetExport, attributes);
info->set_data(Smi::FromInt(index));
- Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
- Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
- info->set_getter(*getter);
- if (!(attributes & ReadOnly)) info->set_setter(*setter);
return info;
}