summaryrefslogtreecommitdiff
path: root/chromium/v8/src/api-natives.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/v8/src/api-natives.cc')
-rw-r--r--chromium/v8/src/api-natives.cc106
1 files changed, 44 insertions, 62 deletions
diff --git a/chromium/v8/src/api-natives.cc b/chromium/v8/src/api-natives.cc
index c95f2ce2553..5993859710a 100644
--- a/chromium/v8/src/api-natives.cc
+++ b/chromium/v8/src/api-natives.cc
@@ -7,6 +7,7 @@
#include "src/api.h"
#include "src/isolate.h"
#include "src/lookup.h"
+#include "src/messages.h"
namespace v8 {
namespace internal {
@@ -36,11 +37,12 @@ MaybeHandle<Object> Instantiate(Isolate* isolate, Handle<Object> data,
}
-MaybeHandle<Object> DefineAccessorProperty(
- Isolate* isolate, Handle<JSObject> object, Handle<Name> name,
- Handle<Object> getter, Handle<Object> setter, Smi* attributes) {
- DCHECK(PropertyDetails::AttributesField::is_valid(
- static_cast<PropertyAttributes>(attributes->value())));
+MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate,
+ Handle<JSObject> object,
+ Handle<Name> name,
+ Handle<Object> getter,
+ Handle<Object> setter,
+ PropertyAttributes attributes) {
if (!getter->IsUndefined()) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, getter,
@@ -55,10 +57,8 @@ MaybeHandle<Object> DefineAccessorProperty(
Handle<FunctionTemplateInfo>::cast(setter)),
Object);
}
- RETURN_ON_EXCEPTION(isolate,
- JSObject::DefineAccessor(
- object, name, getter, setter,
- static_cast<PropertyAttributes>(attributes->value())),
+ RETURN_ON_EXCEPTION(isolate, JSObject::DefineAccessor(object, name, getter,
+ setter, attributes),
Object);
return object;
}
@@ -66,46 +66,29 @@ MaybeHandle<Object> DefineAccessorProperty(
MaybeHandle<Object> DefineDataProperty(Isolate* isolate,
Handle<JSObject> object,
- Handle<Name> key,
+ Handle<Name> name,
Handle<Object> prop_data,
- Smi* unchecked_attributes) {
- DCHECK((unchecked_attributes->value() &
- ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
- // Compute attributes.
- PropertyAttributes attributes =
- static_cast<PropertyAttributes>(unchecked_attributes->value());
-
+ PropertyAttributes attributes) {
Handle<Object> value;
ASSIGN_RETURN_ON_EXCEPTION(isolate, value,
- Instantiate(isolate, prop_data, key), Object);
+ Instantiate(isolate, prop_data, name), Object);
+
+ LookupIterator it = LookupIterator::PropertyOrElement(
+ isolate, object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
#ifdef DEBUG
- bool duplicate;
- if (key->IsName()) {
- LookupIterator it(object, Handle<Name>::cast(key),
- LookupIterator::OWN_SKIP_INTERCEPTOR);
- Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- DCHECK(maybe.IsJust());
- duplicate = it.IsFound();
- } else {
- uint32_t index = 0;
- key->ToArrayIndex(&index);
- Maybe<bool> maybe = JSReceiver::HasOwnElement(object, index);
- if (!maybe.IsJust()) return MaybeHandle<Object>();
- duplicate = maybe.FromJust();
- }
- if (duplicate) {
- Handle<Object> args[1] = {key};
- THROW_NEW_ERROR(isolate, NewTypeError("duplicate_template_property",
- HandleVector(args, 1)),
- Object);
+ Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
+ DCHECK(maybe.IsJust());
+ if (it.IsFound()) {
+ THROW_NEW_ERROR(
+ isolate,
+ NewTypeError(MessageTemplate::kDuplicateTemplateProperty, name),
+ Object);
}
#endif
- RETURN_ON_EXCEPTION(
- isolate, Runtime::DefineObjectProperty(object, key, value, attributes),
- Object);
- return object;
+ return Object::AddDataProperty(&it, value, attributes, STRICT,
+ Object::CERTAINLY_NOT_STORE_FROM_KEYED);
}
@@ -160,27 +143,28 @@ MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj,
HandleScope scope(isolate);
// Disable access checks while instantiating the object.
AccessCheckDisableScope access_check_scope(isolate, obj);
- for (int i = 0; i < properties.length();) {
- int length = Smi::cast(properties.get(i))->value();
- if (length == 3) {
- auto name = handle(Name::cast(properties.get(i + 1)), isolate);
- auto prop_data = handle(properties.get(i + 2), isolate);
- auto attributes = Smi::cast(properties.get(i + 3));
+
+ int i = 0;
+ for (int c = 0; c < data->number_of_properties(); c++) {
+ auto name = handle(Name::cast(properties.get(i++)), isolate);
+ PropertyDetails details(Smi::cast(properties.get(i++)));
+ PropertyAttributes attributes = details.attributes();
+ PropertyKind kind = details.kind();
+
+ if (kind == kData) {
+ auto prop_data = handle(properties.get(i++), isolate);
+
RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
prop_data, attributes),
JSObject);
} else {
- DCHECK(length == 4);
- auto name = handle(Name::cast(properties.get(i + 1)), isolate);
- auto getter = handle(properties.get(i + 2), isolate);
- auto setter = handle(properties.get(i + 3), isolate);
- auto attributes = Smi::cast(properties.get(i + 4));
+ auto getter = handle(properties.get(i++), isolate);
+ auto setter = handle(properties.get(i++), isolate);
RETURN_ON_EXCEPTION(isolate,
DefineAccessorProperty(isolate, obj, name, getter,
setter, attributes),
JSObject);
}
- i += length + 1;
}
return obj;
}
@@ -321,8 +305,8 @@ void AddPropertyToPropertyList(Isolate* isolate, Handle<TemplateInfo> templ,
list = NeanderArray(isolate).value();
templ->set_property_list(*list);
}
+ templ->set_number_of_properties(templ->number_of_properties() + 1);
NeanderArray array(list);
- array.add(isolate, isolate->factory()->NewNumberFromInt(length));
for (int i = 0; i < length; i++) {
Handle<Object> value =
data[i].is_null()
@@ -371,10 +355,9 @@ void ApiNatives::AddDataProperty(Isolate* isolate, Handle<TemplateInfo> info,
Handle<Name> name, Handle<Object> value,
PropertyAttributes attributes) {
const int kSize = 3;
- DCHECK(Smi::IsValid(static_cast<int>(attributes)));
- auto attribute_handle =
- handle(Smi::FromInt(static_cast<int>(attributes)), isolate);
- Handle<Object> data[kSize] = {name, value, attribute_handle};
+ PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
+ auto details_handle = handle(details.AsSmi(), isolate);
+ Handle<Object> data[kSize] = {name, details_handle, value};
AddPropertyToPropertyList(isolate, info, kSize, data);
}
@@ -386,10 +369,9 @@ void ApiNatives::AddAccessorProperty(Isolate* isolate,
Handle<FunctionTemplateInfo> setter,
PropertyAttributes attributes) {
const int kSize = 4;
- DCHECK(Smi::IsValid(static_cast<int>(attributes)));
- auto attribute_handle =
- handle(Smi::FromInt(static_cast<int>(attributes)), isolate);
- Handle<Object> data[kSize] = {name, getter, setter, attribute_handle};
+ PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell);
+ auto details_handle = handle(details.AsSmi(), isolate);
+ Handle<Object> data[kSize] = {name, details_handle, getter, setter};
AddPropertyToPropertyList(isolate, info, kSize, data);
}