Commit 8fab9c9b authored by verwaest's avatar verwaest Committed by Commit bot

Properly prepare boilerplate properties in the parser for the runtime

BUG=

Review URL: https://codereview.chromium.org/1768203002

Cr-Commit-Position: refs/heads/master@{#34582}
parent 4122df26
......@@ -465,18 +465,15 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) {
// much larger than the number of elements, creating an object
// literal with fast elements will be a waste of space.
uint32_t element_index = 0;
if (key->IsString()
&& Handle<String>::cast(key)->AsArrayIndex(&element_index)
&& element_index > max_element_index) {
max_element_index = element_index;
if (key->IsString() && String::cast(*key)->AsArrayIndex(&element_index)) {
max_element_index = Max(element_index, max_element_index);
elements++;
} else if (key->IsSmi()) {
int key_value = Smi::cast(*key)->value();
if (key_value > 0
&& static_cast<uint32_t>(key_value) > max_element_index) {
max_element_index = key_value;
}
key = isolate->factory()->NewNumberFromUint(element_index);
} else if (key->ToArrayIndex(&element_index)) {
max_element_index = Max(element_index, max_element_index);
elements++;
} else if (key->IsNumber()) {
key = isolate->factory()->NumberToString(key);
}
// Add name, value pair to the fixed array.
......
......@@ -86,38 +86,17 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
}
MaybeHandle<Object> maybe_result;
uint32_t element_index = 0;
if (key->IsInternalizedString()) {
if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) {
// Array index as string (uint32).
if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate);
maybe_result = JSObject::SetOwnElementIgnoreAttributes(
boilerplate, element_index, value, NONE);
} else {
Handle<String> name(String::cast(*key));
DCHECK(!name->AsArrayIndex(&element_index));
maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(
boilerplate, name, value, NONE);
}
} else if (key->ToArrayIndex(&element_index)) {
if (key->ToArrayIndex(&element_index)) {
// Array index (uint32).
if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate);
maybe_result = JSObject::SetOwnElementIgnoreAttributes(
boilerplate, element_index, value, NONE);
} else {
// Non-uint32 number.
DCHECK(key->IsNumber());
double num = key->Number();
char arr[100];
Vector<char> buffer(arr, arraysize(arr));
const char* str = DoubleToCString(num, buffer);
Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str);
Handle<String> name = Handle<String>::cast(key);
DCHECK(!name->AsArrayIndex(&element_index));
maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(boilerplate, name,
value, NONE);
}
// If setting the property on the boilerplate throws an
// exception, the exception is converted to an empty handle in
// the handle based operations. In that case, we need to
// convert back to an exception.
RETURN_ON_EXCEPTION(isolate, maybe_result, Object);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment