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) { ...@@ -465,18 +465,15 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) {
// much larger than the number of elements, creating an object // much larger than the number of elements, creating an object
// literal with fast elements will be a waste of space. // literal with fast elements will be a waste of space.
uint32_t element_index = 0; uint32_t element_index = 0;
if (key->IsString() if (key->IsString() && String::cast(*key)->AsArrayIndex(&element_index)) {
&& Handle<String>::cast(key)->AsArrayIndex(&element_index) max_element_index = Max(element_index, max_element_index);
&& element_index > max_element_index) {
max_element_index = element_index;
elements++; elements++;
} else if (key->IsSmi()) { key = isolate->factory()->NewNumberFromUint(element_index);
int key_value = Smi::cast(*key)->value(); } else if (key->ToArrayIndex(&element_index)) {
if (key_value > 0 max_element_index = Max(element_index, max_element_index);
&& static_cast<uint32_t>(key_value) > max_element_index) {
max_element_index = key_value;
}
elements++; elements++;
} else if (key->IsNumber()) {
key = isolate->factory()->NumberToString(key);
} }
// Add name, value pair to the fixed array. // Add name, value pair to the fixed array.
......
...@@ -86,38 +86,17 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate( ...@@ -86,38 +86,17 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
} }
MaybeHandle<Object> maybe_result; MaybeHandle<Object> maybe_result;
uint32_t element_index = 0; uint32_t element_index = 0;
if (key->IsInternalizedString()) { if (key->ToArrayIndex(&element_index)) {
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)) {
// Array index (uint32). // Array index (uint32).
if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate); if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate);
maybe_result = JSObject::SetOwnElementIgnoreAttributes( maybe_result = JSObject::SetOwnElementIgnoreAttributes(
boilerplate, element_index, value, NONE); boilerplate, element_index, value, NONE);
} else { } else {
// Non-uint32 number. Handle<String> name = Handle<String>::cast(key);
DCHECK(key->IsNumber()); DCHECK(!name->AsArrayIndex(&element_index));
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);
maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(boilerplate, name, maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(boilerplate, name,
value, NONE); 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); 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