Remove Function.prototype.toMethod
Function.prototype.toMethod was removed from ES6. This removes the function and updates the tests to either use %ToMethod or a dedicated syntax (using concise method or a class). BUG=v8:3330 LOG=N R=dslomov@chromium.org, adamk Review URL: https://codereview.chromium.org/914713002 Cr-Commit-Position: refs/heads/master@{#26559}
This commit is contained in:
parent
eaad793c2f
commit
68e4897586
1
BUILD.gn
1
BUILD.gn
@ -234,7 +234,6 @@ action("js2c_experimental") {
|
||||
"src/harmony-array.js",
|
||||
"src/harmony-array-includes.js",
|
||||
"src/harmony-typedarray.js",
|
||||
"src/harmony-classes.js",
|
||||
"src/harmony-tostring.js",
|
||||
"src/harmony-templates.js",
|
||||
"src/harmony-regexp.js",
|
||||
|
@ -2213,8 +2213,7 @@ bool Genesis::InstallExperimentalNatives() {
|
||||
static const char* harmony_proxies_natives[] = {"native proxy.js", NULL};
|
||||
static const char* harmony_strings_natives[] = {"native harmony-string.js",
|
||||
NULL};
|
||||
static const char* harmony_classes_natives[] = {"native harmony-classes.js",
|
||||
NULL};
|
||||
static const char* harmony_classes_natives[] = {NULL};
|
||||
static const char* harmony_modules_natives[] = {NULL};
|
||||
static const char* harmony_scoping_natives[] = {NULL};
|
||||
static const char* harmony_object_literals_natives[] = {NULL};
|
||||
|
@ -1,35 +0,0 @@
|
||||
// Copyright 2014 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 file relies on the fact that the following declarations have been made
|
||||
// in runtime.js:
|
||||
// var $Function = global.Function;
|
||||
// var $Array = global.Array;
|
||||
|
||||
"use strict";
|
||||
|
||||
function FunctionToMethod(homeObject) {
|
||||
if (!IS_SPEC_FUNCTION(this)) {
|
||||
throw MakeTypeError('toMethod_non_function',
|
||||
[%ToString(this), typeof this]);
|
||||
|
||||
}
|
||||
|
||||
if (!IS_SPEC_OBJECT(homeObject)) {
|
||||
throw MakeTypeError('toMethod_non_object',
|
||||
[%ToString(homeObject)]);
|
||||
}
|
||||
|
||||
return %ToMethod(this, homeObject);
|
||||
}
|
||||
|
||||
function SetupHarmonyClasses() {
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
InstallFunctions($Function.prototype, DONT_ENUM, $Array(
|
||||
"toMethod", FunctionToMethod
|
||||
));
|
||||
}
|
||||
|
||||
SetupHarmonyClasses();
|
@ -50,8 +50,6 @@ var kMessages = {
|
||||
no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"],
|
||||
apply_non_function: ["Function.prototype.apply was called on ", "%0", ", which is a ", "%1", " and not a function"],
|
||||
apply_wrong_args: ["Function.prototype.apply: Arguments list has wrong type"],
|
||||
toMethod_non_function: ["Function.prototype.toMethod was called on ", "%0", ", which is a ", "%1", " and not a function"],
|
||||
toMethod_non_object: ["Function.prototype.toMethod: home object ", "%0", " is not an object"],
|
||||
flags_getter_non_object: ["RegExp.prototype.flags getter called on non-object ", "%0"],
|
||||
invalid_in_operator_use: ["Cannot use 'in' operator to search for '", "%0", "' in ", "%1"],
|
||||
instanceof_function_expected: ["Expecting a function in instanceof check, but got ", "%0"],
|
||||
|
@ -8710,7 +8710,9 @@ THREADED_TEST(AccessControlGetOwnPropertyNames) {
|
||||
|
||||
|
||||
TEST(SuperAccessControl) {
|
||||
i::FLAG_allow_natives_syntax = true;
|
||||
i::FLAG_harmony_classes = true;
|
||||
i::FLAG_harmony_object_literals = true;
|
||||
v8::Isolate* isolate = CcTest::isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Handle<v8::ObjectTemplate> obj_template =
|
||||
@ -8723,8 +8725,8 @@ TEST(SuperAccessControl) {
|
||||
{
|
||||
v8::TryCatch try_catch;
|
||||
CompileRun(
|
||||
"function f() { return super.hasOwnProperty; };"
|
||||
"var m = f.toMethod(prohibited);"
|
||||
"var f = { m() { return super.hasOwnProperty; } }.m;"
|
||||
"var m = %ToMethod(f, prohibited);"
|
||||
"m();");
|
||||
CHECK(try_catch.HasCaught());
|
||||
}
|
||||
@ -8732,8 +8734,8 @@ TEST(SuperAccessControl) {
|
||||
{
|
||||
v8::TryCatch try_catch;
|
||||
CompileRun(
|
||||
"function f() { return super[42]; };"
|
||||
"var m = f.toMethod(prohibited);"
|
||||
"var f = {m() { return super[42]; } }.m;"
|
||||
"var m = %ToMethod(f, prohibited);"
|
||||
"m();");
|
||||
CHECK(try_catch.HasCaught());
|
||||
}
|
||||
@ -8741,8 +8743,8 @@ TEST(SuperAccessControl) {
|
||||
{
|
||||
v8::TryCatch try_catch;
|
||||
CompileRun(
|
||||
"function f() { super.hasOwnProperty = function () {}; };"
|
||||
"var m = f.toMethod(prohibited);"
|
||||
"var f = {m() { super.hasOwnProperty = function () {}; } }.m;"
|
||||
"var m = %ToMethod(f, prohibited);"
|
||||
"m();");
|
||||
CHECK(try_catch.HasCaught());
|
||||
}
|
||||
@ -8751,11 +8753,13 @@ TEST(SuperAccessControl) {
|
||||
v8::TryCatch try_catch;
|
||||
CompileRun(
|
||||
"Object.defineProperty(Object.prototype, 'x', { set : function(){}});"
|
||||
"function f() { "
|
||||
" 'use strict';"
|
||||
" super.x = function () {}; "
|
||||
"};"
|
||||
"var m = f.toMethod(prohibited);"
|
||||
"var f = {"
|
||||
" m() { "
|
||||
" 'use strict';"
|
||||
" super.x = function () {};"
|
||||
" }"
|
||||
"}.m;"
|
||||
"var m = %ToMethod(f, prohibited);"
|
||||
"m();");
|
||||
CHECK(try_catch.HasCaught());
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-classes
|
||||
// Flags: --harmony-classes --allow-natives-syntax
|
||||
|
||||
(function TestSuperNamedLoads() {
|
||||
function Base() { }
|
||||
@ -40,15 +40,22 @@
|
||||
|
||||
|
||||
(function TestSuperKeyedLoads() {
|
||||
'use strict';
|
||||
|
||||
var x = 'x';
|
||||
var derivedDataProperty = 'derivedDataProperty';
|
||||
var f = 'f';
|
||||
|
||||
function Base() { }
|
||||
function fBase() { return "Base " + this.toString(); }
|
||||
Base.prototype[f] = fBase.toMethod(Base.prototype);
|
||||
class Base {
|
||||
f() {
|
||||
return "Base " + this.toString();
|
||||
}
|
||||
toString() {
|
||||
return "this is Base";
|
||||
}
|
||||
}
|
||||
|
||||
Base.prototype[x] = 15;
|
||||
Base.prototype.toString = function() { return "this is Base"; };
|
||||
|
||||
function Derived() {
|
||||
this[derivedDataProperty] = "xxx";
|
||||
@ -79,7 +86,7 @@
|
||||
|
||||
function Base() { }
|
||||
function fBase() { return "Base " + this.toString(); }
|
||||
Base.prototype[f] = fBase.toMethod(Base.prototype);
|
||||
Base.prototype[f] = %ToMethod(fBase, Base.prototype);
|
||||
Base.prototype[x] = 15;
|
||||
Base.prototype.toString = function() { return "this is Base"; };
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
function ClassD() { }
|
||||
|
||||
assertEquals(1, f(1));
|
||||
var g = f.toMethod(ClassD.prototype);
|
||||
var g = %ToMethod(f, ClassD.prototype);
|
||||
assertEquals(1, g(1));
|
||||
assertEquals(undefined, f[%HomeObjectSymbol()]);
|
||||
assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]);
|
||||
@ -33,22 +33,13 @@
|
||||
var q = f(0);
|
||||
assertEquals(2, q(1));
|
||||
assertEquals(3, q(1));
|
||||
var g = q.toMethod(Derived.prototype);
|
||||
var g = %ToMethod(q, Derived.prototype);
|
||||
assertFalse(g === q);
|
||||
assertEquals(4, g(1));
|
||||
assertEquals(5, q(1));
|
||||
}());
|
||||
|
||||
|
||||
(function TestErrorCases() {
|
||||
var sFun = Function.prototype.toMethod;
|
||||
assertThrows(function() { sFun.call({}); }, TypeError);
|
||||
assertThrows(function() { sFun.call({}, {}); }, TypeError);
|
||||
function f(){};
|
||||
assertThrows(function() { f.toMethod(1); }, TypeError);
|
||||
}());
|
||||
|
||||
|
||||
(function TestPrototypeChain() {
|
||||
var o = {};
|
||||
var o1 = {};
|
||||
@ -56,11 +47,11 @@
|
||||
|
||||
function g() { }
|
||||
|
||||
var fMeth = f.toMethod(o);
|
||||
var fMeth = %ToMethod(f, o);
|
||||
assertEquals(o, fMeth[%HomeObjectSymbol()]);
|
||||
g.__proto__ = fMeth;
|
||||
assertEquals(undefined, g[%HomeObjectSymbol()]);
|
||||
var gMeth = g.toMethod(o1);
|
||||
var gMeth = %ToMethod(g, o1);
|
||||
assertEquals(fMeth, gMeth.__proto__);
|
||||
assertEquals(o, fMeth[%HomeObjectSymbol()]);
|
||||
assertEquals(o1, gMeth[%HomeObjectSymbol()]);
|
||||
@ -82,7 +73,7 @@
|
||||
}
|
||||
|
||||
var fBound = f.bind(o, 1, 2, 3);
|
||||
var fMeth = fBound.toMethod(p);
|
||||
var fMeth = %ToMethod(fBound, p);
|
||||
assertEquals(10, fMeth(4));
|
||||
assertEquals(10, fMeth.call(p, 4));
|
||||
var fBound1 = fBound.bind(o, 4);
|
||||
@ -100,7 +91,7 @@
|
||||
assertEquals(15, f(o));
|
||||
%OptimizeFunctionOnNextCall(f);
|
||||
assertEquals(15, f(o));
|
||||
var g = f.toMethod({});
|
||||
var g = %ToMethod(f, {});
|
||||
var o1 = {y : 1024, x : "abc"};
|
||||
assertEquals("abc", f(o1));
|
||||
assertEquals("abc", g(o1));
|
||||
@ -110,6 +101,6 @@
|
||||
function f() {}
|
||||
Object.preventExtensions(f);
|
||||
assertFalse(Object.isExtensible(f));
|
||||
var m = f.toMethod({});
|
||||
var m = %ToMethod(f, {});
|
||||
assertTrue(Object.isExtensible(m));
|
||||
}());
|
||||
|
@ -1706,7 +1706,6 @@
|
||||
'../../src/harmony-array-includes.js',
|
||||
'../../src/harmony-tostring.js',
|
||||
'../../src/harmony-typedarray.js',
|
||||
'../../src/harmony-classes.js',
|
||||
'../../src/harmony-templates.js',
|
||||
'../../src/harmony-regexp.js'
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user