Use C++ implementation of Object.definePropert{y,ies}

For now, only rewire builtins in v8natives.js to call the new runtime functions.

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

Cr-Commit-Position: refs/heads/master@{#31413}
This commit is contained in:
jkummerow 2015-10-20 07:29:22 -07:00 committed by Commit bot
parent a64d387ad2
commit b2abc0e3ad
5 changed files with 66 additions and 72 deletions

View File

@ -1032,42 +1032,47 @@ function ObjectCreate(proto, properties) {
// ES5 section 15.2.3.6.
function ObjectDefineProperty(obj, p, attributes) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty");
}
var name = TO_NAME(p);
if (%_IsJSProxy(obj)) {
// Clone the attributes object for protection.
// TODO(rossberg): not spec'ed yet, so not sure if this should involve
// non-own properties as it does (or non-enumerable ones, as it doesn't?).
var attributesClone = { __proto__: null };
for (var a in attributes) {
attributesClone[a] = attributes[a];
// The new pure-C++ implementation doesn't support Proxies yet, nor O.o.
// TODO(jkummerow): Implement missing features and remove fallback path.
if (%_IsJSProxy(obj) || %IsObserved(obj)) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty");
}
DefineProxyProperty(obj, name, attributesClone, true);
// The following would implement the spec as in the current proposal,
// but after recent comments on es-discuss, is most likely obsolete.
/*
var defineObj = FromGenericPropertyDescriptor(desc);
var names = ObjectGetOwnPropertyNames(attributes);
var standardNames =
{value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0};
for (var i = 0; i < names.length; i++) {
var N = names[i];
if (!(%HasOwnProperty(standardNames, N))) {
var attr = GetOwnPropertyJS(attributes, N);
DefineOwnProperty(descObj, N, attr, true);
var name = TO_NAME(p);
if (%_IsJSProxy(obj)) {
// Clone the attributes object for protection.
// TODO(rossberg): not spec'ed yet, so not sure if this should involve
// non-own properties as it does (or non-enumerable ones, as it doesn't?).
var attributesClone = { __proto__: null };
for (var a in attributes) {
attributesClone[a] = attributes[a];
}
DefineProxyProperty(obj, name, attributesClone, true);
// The following would implement the spec as in the current proposal,
// but after recent comments on es-discuss, is most likely obsolete.
/*
var defineObj = FromGenericPropertyDescriptor(desc);
var names = ObjectGetOwnPropertyNames(attributes);
var standardNames =
{value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0};
for (var i = 0; i < names.length; i++) {
var N = names[i];
if (!(%HasOwnProperty(standardNames, N))) {
var attr = GetOwnPropertyJS(attributes, N);
DefineOwnProperty(descObj, N, attr, true);
}
}
// This is really confusing the types, but it is what the proxies spec
// currently requires:
desc = descObj;
*/
} else {
var desc = ToPropertyDescriptor(attributes);
DefineOwnProperty(obj, name, desc, true);
}
// This is really confusing the types, but it is what the proxies spec
// currently requires:
desc = descObj;
*/
} else {
var desc = ToPropertyDescriptor(attributes);
DefineOwnProperty(obj, name, desc, true);
return obj;
}
return obj;
return %ObjectDefineProperty(obj, p, attributes);
}
@ -1095,19 +1100,24 @@ function GetOwnEnumerablePropertyNames(object) {
// ES5 section 15.2.3.7.
function ObjectDefineProperties(obj, properties) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
// The new pure-C++ implementation doesn't support Proxies yet, nor O.o.
// TODO(jkummerow): Implement missing features and remove fallback path.
if (%_IsJSProxy(obj) || %_IsJSProxy(properties) || %IsObserved(obj)) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
}
var props = TO_OBJECT(properties);
var names = GetOwnEnumerablePropertyNames(props);
var descriptors = new InternalArray();
for (var i = 0; i < names.length; i++) {
descriptors.push(ToPropertyDescriptor(props[names[i]]));
}
for (var i = 0; i < names.length; i++) {
DefineOwnProperty(obj, names[i], descriptors[i], true);
}
return obj;
}
var props = TO_OBJECT(properties);
var names = GetOwnEnumerablePropertyNames(props);
var descriptors = new InternalArray();
for (var i = 0; i < names.length; i++) {
descriptors.push(ToPropertyDescriptor(props[names[i]]));
}
for (var i = 0; i < names.length; i++) {
DefineOwnProperty(obj, names[i], descriptors[i], true);
}
return obj;
return %ObjectDefineProperties(obj, properties);
}

View File

@ -6515,7 +6515,7 @@ bool JSArray::ArraySetLength(Isolate* isolate, Handle<JSArray> a,
if (!success && should_throw == THROW_ON_ERROR) {
isolate->Throw(*isolate->factory()->NewTypeError(
MessageTemplate::kStrictDeleteProperty,
isolate->factory()->NewNumberFromUint(actual_new_len - 1)));
isolate->factory()->NewNumberFromUint(actual_new_len - 1), a));
}
return success;
}
@ -7783,7 +7783,10 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
DCHECK(filter == INCLUDE_SYMBOLS);
PropertyAttributes attr_filter =
static_cast<PropertyAttributes>(DONT_ENUM | PRIVATE_SYMBOL);
JSObject::CollectOwnElementKeys(current, &accumulator, attr_filter);
Handle<FixedArray> property_keys = isolate->factory()->NewFixedArray(
current->NumberOfOwnProperties(attr_filter));
current->GetOwnPropertyNames(*property_keys, 0, attr_filter);
accumulator.AddKeys(property_keys);
}
// Add the property keys from the interceptor.

View File

@ -4,6 +4,7 @@
#include "src/property-descriptor.h"
#include "src/bootstrapper.h"
#include "src/factory.h"
#include "src/isolate-inl.h"
#include "src/lookup.h"
@ -43,6 +44,9 @@ bool ToPropertyDescriptorFastPath(Isolate* isolate, Handle<Object> obj,
if (map->instance_type() != JS_OBJECT_TYPE) return false;
if (map->is_access_check_needed()) return false;
if (map->prototype() != *isolate->initial_object_prototype()) return false;
// During bootstrapping, the object_function_prototype_map hasn't been
// set up yet.
if (isolate->bootstrapper()->IsActive()) return false;
if (JSObject::cast(map->prototype())->map() !=
isolate->native_context()->object_function_prototype_map()) {
return false;

View File

@ -8728,9 +8728,10 @@ TEST(AccessControlES5) {
CHECK_EQ(42, g_echo_value);
v8::Handle<Value> value;
CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})");
value = CompileRun("other.accessible_prop == 42");
CompileRun("Object.defineProperty(other, 'accessible_prop', {value: 43})");
value = CompileRun("other.accessible_prop == 43");
CHECK(value->IsTrue());
CHECK_EQ(43, g_echo_value); // Make sure we didn't overwrite the setter.
}

View File

@ -33,30 +33,6 @@
'intl402/11.2.3_b': [FAIL],
'intl402/12.2.3_b': [FAIL],
# BUG(v8:4267)
'built-ins/Object/defineProperties/15.2.3.7-6-a-112': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-113': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-164': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-165': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-166': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-168': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-169': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-170': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-172': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-173': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-175': [FAIL],
'built-ins/Object/defineProperties/15.2.3.7-6-a-176': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-116': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-117': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-168': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-169': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-170': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-172': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-173': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-174': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-176': [FAIL],
'built-ins/Object/defineProperty/15.2.3.6-4-177': [FAIL],
# Unicode canonicalization is not available with i18n turned off.
'built-ins/String/prototype/localeCompare/15.5.4.9_CE': [['no_i18n', SKIP]],