Remove Reflect.enumerate

The Proxy enumerate trap and Reflect.enumerate are removed from the
ES2016 draft specification. This patch removes the Reflect.enumerate
function, and a follow-on patch will be responsible for the Proxy
trap changes.

R=adamk
LOG=Y
BUG=v8:4768

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

Cr-Commit-Position: refs/heads/master@{#34196}
This commit is contained in:
littledan 2016-02-22 11:09:37 -08:00 committed by Commit bot
parent a686f4f97c
commit 0b53b7d36b
12 changed files with 15 additions and 413 deletions

View File

@ -300,7 +300,6 @@ action("js2c_experimental") {
"src/js/generator.js",
"src/js/harmony-atomics.js",
"src/js/harmony-regexp.js",
"src/js/harmony-reflect.js",
"src/js/harmony-object-observe.js",
"src/js/harmony-sharedarraybuffer.js",
"src/js/harmony-simd.js",

View File

@ -2081,24 +2081,6 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
WELL_KNOWN_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL)
#undef EXPORT_PUBLIC_SYMBOL
{
Handle<JSFunction> apply = InstallFunction(
container, "reflect_apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
MaybeHandle<JSObject>(), Builtins::kReflectApply);
apply->shared()->DontAdaptArguments();
apply->shared()->set_length(3);
native_context->set_reflect_apply(*apply);
}
{
Handle<JSFunction> construct = InstallFunction(
container, "reflect_construct", JS_OBJECT_TYPE, JSObject::kHeaderSize,
MaybeHandle<JSObject>(), Builtins::kReflectConstruct);
construct->shared()->DontAdaptArguments();
construct->shared()->set_length(2);
native_context->set_reflect_construct(*construct);
}
{
Handle<JSFunction> to_string = InstallFunction(
container, "object_to_string", JS_OBJECT_TYPE, JSObject::kHeaderSize,
@ -2413,6 +2395,15 @@ void Genesis::InitializeGlobal_harmony_reflect() {
Builtins::kReflectDeleteProperty, 2, true);
native_context()->set_reflect_delete_property(*delete_property);
Handle<JSFunction> apply = SimpleCreateFunction(
isolate(), factory->apply_string(), Builtins::kReflectApply, 3, false);
native_context()->set_reflect_apply(*apply);
Handle<JSFunction> construct =
SimpleCreateFunction(isolate(), factory->construct_string(),
Builtins::kReflectConstruct, 2, false);
native_context()->set_reflect_construct(*construct);
if (!FLAG_harmony_reflect) return;
Handle<JSGlobalObject> global(JSGlobalObject::cast(
@ -2424,6 +2415,8 @@ void Genesis::InitializeGlobal_harmony_reflect() {
InstallFunction(reflect, define_property, factory->defineProperty_string());
InstallFunction(reflect, delete_property, factory->deleteProperty_string());
InstallFunction(reflect, apply, factory->apply_string());
InstallFunction(reflect, construct, factory->construct_string());
SimpleInstallFunction(reflect, factory->get_string(),
Builtins::kReflectGet, 2, false);

View File

@ -1,37 +0,0 @@
// Copyright 2013-2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function(global, utils) {
'use strict';
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalReflect = global.Reflect;
var MakeTypeError;
var ReflectApply = utils.ImportNow("reflect_apply");
var ReflectConstruct = utils.ImportNow("reflect_construct");
utils.Import(function(from) {
MakeTypeError = from.MakeTypeError;
});
// -------------------------------------------------------------------
function ReflectEnumerate(obj) {
if (!IS_RECEIVER(obj))
throw MakeTypeError(kCalledOnNonObject, "Reflect.enumerate")
return (function* () { for (var x in obj) yield x })();
}
utils.InstallFunctions(GlobalReflect, DONT_ENUM, [
"apply", ReflectApply,
"construct", ReflectConstruct,
"enumerate", ReflectEnumerate
]);
})

View File

@ -16,7 +16,6 @@ for (var key of Object.keys(object)) assertUnreachable();
for (var key of Object.getOwnPropertySymbols(object)) assertUnreachable();
for (var key of Object.getOwnPropertyNames(object)) assertUnreachable();
for (var key of Reflect.ownKeys(object)) assertUnreachable();
for (var key of Reflect.enumerate(object)) assertUnreachable();
for (var key in object) assertUnreachable();
var object2 = {__proto__: object};
@ -24,7 +23,6 @@ for (var key of Object.keys(object2)) assertUnreachable();
for (var key of Object.getOwnPropertySymbols(object2)) assertUnreachable();
for (var key of Object.getOwnPropertyNames(object2)) assertUnreachable();
for (var key of Reflect.ownKeys(object2)) assertUnreachable();
for (var key of Reflect.enumerate(object2)) assertUnreachable();
for (var key in object2) assertUnreachable();

View File

@ -1,53 +0,0 @@
// Copyright 2010-2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test that properties deleted during an enumeration do not show up in
// the enumeration. This is adapted from mjsunit/for-in-delete.js.
// Flags: --harmony-reflect
function f(o, expected, del) {
var index = 0;
for (p of Reflect.enumerate(o)) {
if (del) delete o[del];
assertEquals(expected[index], p);
index++;
}
assertEquals(expected.length, index);
}
var o = {}
o.a = 1;
o.b = 2;
o.c = 3;
o.d = 3;
f(o, ['a', 'b', 'c', 'd']);
f(o, ['a', 'b', 'c', 'd']);
f(o, ['a', 'c', 'd'], 'b');
f(o, ['a', 'c'], 'd');

View File

@ -1,78 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This is adapted from mjsunit/for-in-opt.js.
// Flags: --harmony-proxies --harmony-reflect --allow-natives-syntax
"use strict";
function f(o) {
var result = [];
for (var i of Reflect.enumerate(Object(o))) {
result.push(i);
}
return result;
}
assertEquals(["0"], f("a"));
assertEquals(["0"], f("a"));
%OptimizeFunctionOnNextCall(f);
assertEquals(["0","1","2"], f("bla"));
// Test the lazy deopt points.
var keys = ["a", "b", "c", "d"];
var has_keys = [];
var deopt_has = false;
var deopt_enum = false;
var handler = {
enumerate: function(target) {
if (deopt_enum) {
%DeoptimizeFunction(f2);
deopt_enum = false;
}
return keys;
},
getPropertyDescriptor: function(k) {
if (deopt_has) {
%DeoptimizeFunction(f2);
deopt_has = false;
}
has_keys.push(k);
return {value: 10, configurable: true, writable: false, enumerable: true};
}
};
// TODO(neis,cbruni): Enable once the enumerate proxy trap is properly
// implemented.
// var proxy = new Proxy({}, handler);
// var o = {__proto__: proxy};
//
// function f2(o) {
// var result = [];
// for (var i of Reflect.enumerate(o)) {
// result.push(i);
// }
// return result;
// }
//
// function check_f2() {
// assertEquals(keys, f2(o));
// assertEquals(keys, has_keys);
// has_keys.length = 0;
// }
//
// check_f2();
// check_f2();
// Test lazy deopt after ForInEnumerate
// %OptimizeFunctionOnNextCall(f2);
// deopt_enum = true;
// check_f2();
// Test lazy deopt after FILTER_KEY
// %OptimizeFunctionOnNextCall(f2);
// deopt_has = true;
// check_f2();

View File

@ -1,88 +0,0 @@
// Copyright 2008-2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This is adapted from mjsunit/for-in-special-cases.js.
// Flags: --harmony-reflect
function Accumulate(x) {
var accumulator = "";
for (var i of Reflect.enumerate(Object(x))) {
accumulator += i;
}
return accumulator;
}
for (var i = 0; i < 3; ++i) {
var elements = Accumulate("abcd");
// We do not assume that enumerate enumerates elements in order.
assertTrue(-1 != elements.indexOf("0"));
assertTrue(-1 != elements.indexOf("1"));
assertTrue(-1 != elements.indexOf("2"));
assertTrue(-1 != elements.indexOf("3"));
assertEquals(4, elements.length);
}
function for_in_string_prototype() {
var x = new String("abc");
x.foo = 19;
function B() {
this.bar = 5;
this[7] = 4;
}
B.prototype = x;
var y = new B();
y.gub = 13;
var elements = Accumulate(y);
var elements1 = Accumulate(y);
// If enumerate returns elements in a different order on multiple calls, this
// assert will fail. If that happens, consider if that behavior is OK.
assertEquals(elements, elements1, "Enumeration not the same both times.");
// We do not assume that enumerate enumerates elements in order.
assertTrue(-1 != elements.indexOf("0"));
assertTrue(-1 != elements.indexOf("1"));
assertTrue(-1 != elements.indexOf("2"));
assertTrue(-1 != elements.indexOf("7"));
assertTrue(-1 != elements.indexOf("foo"));
assertTrue(-1 != elements.indexOf("bar"));
assertTrue(-1 != elements.indexOf("gub"));
assertEquals(13, elements.length);
elements = Accumulate(x);
assertTrue(-1 != elements.indexOf("0"));
assertTrue(-1 != elements.indexOf("1"));
assertTrue(-1 != elements.indexOf("2"));
assertTrue(-1 != elements.indexOf("foo"));
assertEquals(6, elements.length);
}
for_in_string_prototype();
for_in_string_prototype();

View File

@ -1,101 +0,0 @@
// Copyright 2008-2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This is adapted from mjsunit/for-in.js.
// Flags: --harmony-reflect
function props(x) {
var array = [];
for (var p of Reflect.enumerate(x)) array.push(p);
return array.sort();
}
assertEquals(0, props({}).length, "olen0");
assertEquals(1, props({x:1}).length, "olen1");
assertEquals(2, props({x:1, y:2}).length, "olen2");
assertArrayEquals(["x"], props({x:1}), "x");
assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy");
assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom");
assertEquals(0, props([]).length, "alen0");
assertEquals(1, props([1]).length, "alen1");
assertEquals(2, props([1,2]).length, "alen2");
assertArrayEquals(["0"], props([1]), "0");
assertArrayEquals(["0", "1"], props([1,2]), "01");
assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012");
var o = {};
var a = [];
for (var i = 0x0020; i < 0x01ff; i+=2) {
var s = 'char:' + String.fromCharCode(i);
a.push(s);
o[s] = i;
}
assertArrayEquals(a, props(o), "charcodes");
var a = [];
assertEquals(0, props(a).length, "proplen0");
a[Math.pow(2,30)-1] = 0;
assertEquals(1, props(a).length, "proplen1");
a[Math.pow(2,31)-1] = 0;
assertEquals(2, props(a).length, "proplen2");
a[1] = 0;
assertEquals(3, props(a).length, "proplen3");
var result = '';
for (var p of Reflect.enumerate({a : [0], b : 1})) { result += p; }
assertEquals('ab', result, "ab");
var result = '';
for (var p of Reflect.enumerate({a : {v:1}, b : 1})) { result += p; }
assertEquals('ab', result, "ab-nodeep");
var result = '';
for (var p of Reflect.enumerate({ get a() {}, b : 1})) { result += p; }
assertEquals('ab', result, "abget");
var result = '';
for (var p of Reflect.enumerate({ get a() {}, set a(x) {}, b : 1})) {
result += p;
}
assertEquals('ab', result, "abgetset");
(function() {
var large_key = 2147483650;
var o = {__proto__: {}};
o[large_key] = 1;
o.__proto__[large_key] = 1;
var keys = [];
for (var k of Reflect.enumerate(o)) {
keys.push(k);
}
assertEquals(["2147483650"], keys);
})();

View File

@ -486,27 +486,6 @@ function prepare(target) {
})();
////////////////////////////////////////////////////////////////////////////////
// Reflect.enumerate
(function testReflectEnumerateArity() {
assertEquals(1, Reflect.enumerate.length);
})();
(function testReflectEnumerateOnNonObject() {
assertThrows(function() { Reflect.enumerate(); }, TypeError);
assertThrows(function() { Reflect.enumerate(42); }, TypeError);
assertThrows(function() { Reflect.enumerate(null); }, TypeError);
})();
// See reflect-enumerate*.js for further tests.
////////////////////////////////////////////////////////////////////////////////
// Reflect.getOwnPropertyDescriptor

View File

@ -810,12 +810,9 @@
'es6/typedarray': [FAIL],
'es6/regress/regress-2681': [FAIL],
'es6/regress/regress-2691': [FAIL],
'es6/regress/regress-455141': [FAIL],
'es6/regress/regress-3280': [FAIL],
'harmony/destructuring-parameters-literalcount-nolazy': [FAIL],
'harmony/destructuring-assignment': [FAIL],
'harmony/function-sent': [FAIL],
'harmony/private-symbols': [FAIL],
'harmony/reflect-enumerate-delete': [FAIL],
'harmony/reflect-enumerate-special-cases': [FAIL],
'harmony/proxies-enumerate': [FAIL],
@ -823,13 +820,10 @@
'harmony/reflect-enumerate': [FAIL],
'harmony/destructuring': [FAIL],
'harmony/regress/regress-4482': [FAIL],
'harmony/reflect': [FAIL],
'harmony/generators': [FAIL],
'harmony/iterator-close': [FAIL],
'regress/regress-572589': [FAIL],
'harmony/reflect-construct': [FAIL],
'es6/promises': [FAIL],
'deserialize-optimize-inner': [FAIL],
# TODO(rmcilroy,4680): Check failed in
# BytecodeGenerator::VisitFunctionLiteral - !shared_info.is_null().

View File

@ -47,13 +47,10 @@
###################### MISSING ES6 FEATURES #######################
# It's unclear what the right behavior for [[Enumerate]] is; we're awaiting
# clarification in the spec. Currently, our for-in implementation for
# Proxies checks all trap result values for being strings...
'built-ins/Proxy/enumerate/return-trap-result': [FAIL],
# ...and our Reflect.enumerate implementation is built on for-in by wrapping
# the iteration's results in a new generator; this postpones exceptions.
'built-ins/Reflect/enumerate/return-abrupt-from-result': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=4768
# The Reflect.enumerate trap is removed
'built-ins/Reflect/enumerate/*': [SKIP],
'built-ins/Proxy/enumerate/*': [SKIP],
# https://code.google.com/p/v8/issues/detail?id=4163
'built-ins/GeneratorPrototype/next/context-constructor-invocation': [FAIL],

View File

@ -2010,7 +2010,6 @@
'../../src/js/generator.js',
'../../src/js/harmony-atomics.js',
'../../src/js/harmony-regexp.js',
'../../src/js/harmony-reflect.js',
'../../src/js/harmony-object-observe.js',
'../../src/js/harmony-sharedarraybuffer.js',
'../../src/js/harmony-simd.js',