From ff2c9eace4cd987de3efcfdddc92143ede5d2c76 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Thu, 24 Sep 2015 21:04:28 -0700 Subject: [PATCH] [es6] Remove left-overs from Function.prototype.toMethod. The actual Function.prototype.toMethod was removed some time already, but there were some stuff (esp. %ToMethod) left in the tree, including tests for %ToMethod. This code (and esp. the tests) cause trouble in the process of moving bound functions away from JSFunction; so since the code is unused anyway, we can as well remove it. The original removal of Function.prototype.toMethod was in February 2015 in 68e489758607bb7373409b49a0a7883407a322b3. R=jarin@chromium.org BUG=v8:3330 LOG=n Review URL: https://codereview.chromium.org/1366063002 Cr-Commit-Position: refs/heads/master@{#30925} --- src/objects.cc | 24 -------- src/objects.h | 5 -- src/runtime/runtime-classes.cc | 13 ---- src/runtime/runtime.h | 1 - test/cctest/test-api.cc | 54 ----------------- test/mjsunit/es6/toMethod.js | 106 --------------------------------- test/mjsunit/harmony/super.js | 33 ---------- 7 files changed, 236 deletions(-) delete mode 100644 test/mjsunit/es6/toMethod.js diff --git a/src/objects.cc b/src/objects.cc index 3e88c961e..02d8d3481 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -10134,30 +10134,6 @@ void JSFunction::AttemptConcurrentOptimization() { } -Handle JSFunction::CloneClosure(Handle function) { - Isolate* isolate = function->GetIsolate(); - Handle map(function->map()); - Handle shared(function->shared()); - Handle context(function->context()); - Handle clone = - isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); - - if (shared->bound()) { - clone->set_function_bindings(function->function_bindings()); - } - - // In typical case, __proto__ of ``function`` is the default Function - // prototype, which means that SetPrototype below is a no-op. - // In rare cases when that is not true, we mutate the clone's __proto__. - Handle original_prototype(map->prototype(), isolate); - if (*original_prototype != clone->map()->prototype()) { - JSObject::SetPrototype(clone, original_prototype, false).Assert(); - } - - return clone; -} - - void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( Handle shared, Handle code) { Isolate* isolate = shared->GetIsolate(); diff --git a/src/objects.h b/src/objects.h index 6f849584a..6838f275b 100644 --- a/src/objects.h +++ b/src/objects.h @@ -7141,11 +7141,6 @@ class JSFunction: public JSObject { static void SetInstancePrototype(Handle function, Handle value); - // Creates a new closure for the fucntion with the same bindings, - // bound values, and prototype. An equivalent of spec operations - // ``CloneMethod`` and ``CloneBoundFunction``. - static Handle CloneClosure(Handle function); - // After prototype is removed, it will not be created when accessed, and // [[Construct]] from this function will not be allowed. bool RemovePrototype(); diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc index 5219a6882..51e682f32 100644 --- a/src/runtime/runtime-classes.cc +++ b/src/runtime/runtime-classes.cc @@ -74,19 +74,6 @@ RUNTIME_FUNCTION(Runtime_ThrowIfStaticPrototype) { } -RUNTIME_FUNCTION(Runtime_ToMethod) { - HandleScope scope(isolate); - DCHECK(args.length() == 2); - CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); - CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); - Handle clone = JSFunction::CloneClosure(fun); - Handle home_object_symbol(isolate->factory()->home_object_symbol()); - JSObject::SetOwnPropertyIgnoreAttributes(clone, home_object_symbol, - home_object, DONT_ENUM).Assert(); - return *clone; -} - - RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { DCHECK(args.length() == 0); return isolate->heap()->home_object_symbol(); diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index fd8b93997..a3bc2125c 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -80,7 +80,6 @@ namespace internal { F(ThrowArrayNotSubclassableError, 0, 1) \ F(ThrowStaticPrototypeError, 0, 1) \ F(ThrowIfStaticPrototype, 1, 1) \ - F(ToMethod, 2, 1) \ F(HomeObjectSymbol, 0, 1) \ F(DefineClass, 5, 1) \ F(FinalizeClassDefinition, 2, 1) \ diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 197634dc3..d55ad6915 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -8792,60 +8792,6 @@ THREADED_TEST(AccessControlGetOwnPropertyNames) { } -TEST(SuperAccessControl) { - i::FLAG_allow_natives_syntax = true; - v8::Isolate* isolate = CcTest::isolate(); - v8::HandleScope handle_scope(isolate); - v8::Handle obj_template = - v8::ObjectTemplate::New(isolate); - obj_template->SetAccessCheckCallbacks(AccessAlwaysBlocked, NULL); - LocalContext env; - env->Global()->Set(v8_str("prohibited"), obj_template->NewInstance()); - - { - v8::TryCatch try_catch(isolate); - CompileRun( - "var f = { m() { return super.hasOwnProperty; } }.m;" - "var m = %ToMethod(f, prohibited);" - "m();"); - CHECK(try_catch.HasCaught()); - } - - { - v8::TryCatch try_catch(isolate); - CompileRun( - "var f = {m() { return super[42]; } }.m;" - "var m = %ToMethod(f, prohibited);" - "m();"); - CHECK(try_catch.HasCaught()); - } - - { - v8::TryCatch try_catch(isolate); - CompileRun( - "var f = {m() { super.hasOwnProperty = function () {}; } }.m;" - "var m = %ToMethod(f, prohibited);" - "m();"); - CHECK(try_catch.HasCaught()); - } - - { - v8::TryCatch try_catch(isolate); - CompileRun( - "Object.defineProperty(Object.prototype, 'x', { set : function(){}});" - "var f = {" - " m() { " - " 'use strict';" - " super.x = function () {};" - " }" - "}.m;" - "var m = %ToMethod(f, prohibited);" - "m();"); - CHECK(try_catch.HasCaught()); - } -} - - TEST(Regress470113) { v8::Isolate* isolate = CcTest::isolate(); v8::HandleScope handle_scope(isolate); diff --git a/test/mjsunit/es6/toMethod.js b/test/mjsunit/es6/toMethod.js deleted file mode 100644 index c18251b2d..000000000 --- a/test/mjsunit/es6/toMethod.js +++ /dev/null @@ -1,106 +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. -// -// Flags: --allow-natives-syntax - - -(function TestSingleClass() { - function f(x) { - var a = [0, 1, 2] - return a[x]; - } - - function ClassD() { } - - assertEquals(1, f(1)); - var g = %ToMethod(f, ClassD.prototype); - assertEquals(1, g(1)); - assertEquals(undefined, f[%HomeObjectSymbol()]); - assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]); -}()); - - -(function TestClassHierarchy() { - function f(x) { - return function g(y) { x++; return x + y; }; - } - - function Base() {} - function Derived() { } - Derived.prototype = Object.create(Base.prototype); - - var q = f(0); - assertEquals(2, q(1)); - assertEquals(3, q(1)); - var g = %ToMethod(q, Derived.prototype); - assertFalse(g === q); - assertEquals(4, g(1)); - assertEquals(5, q(1)); -}()); - - -(function TestPrototypeChain() { - var o = {}; - var o1 = {}; - function f() { } - - function g() { } - - var fMeth = %ToMethod(f, o); - assertEquals(o, fMeth[%HomeObjectSymbol()]); - g.__proto__ = fMeth; - assertEquals(undefined, g[%HomeObjectSymbol()]); - var gMeth = %ToMethod(g, o1); - assertEquals(fMeth, gMeth.__proto__); - assertEquals(o, fMeth[%HomeObjectSymbol()]); - assertEquals(o1, gMeth[%HomeObjectSymbol()]); -}()); - - -(function TestBoundFunction() { - var o = {}; - var p = {}; - - - function f(x, y, z, w) { - assertEquals(o, this); - assertEquals(1, x); - assertEquals(2, y); - assertEquals(3, z); - assertEquals(4, w); - return x+y+z+w; - } - - var fBound = f.bind(o, 1, 2, 3); - var fMeth = %ToMethod(fBound, p); - assertEquals(10, fMeth(4)); - assertEquals(10, fMeth.call(p, 4)); - var fBound1 = fBound.bind(o, 4); - assertEquals(10, fBound1()); - var fMethBound = fMeth.bind(o, 4); - assertEquals(10, fMethBound()); -}()); - -(function TestOptimized() { - function f(o) { - return o.x; - } - var o = {x : 15}; - assertEquals(15, f(o)); - assertEquals(15, f(o)); - %OptimizeFunctionOnNextCall(f); - assertEquals(15, f(o)); - var g = %ToMethod(f, {}); - var o1 = {y : 1024, x : "abc"}; - assertEquals("abc", f(o1)); - assertEquals("abc", g(o1)); -} ()); - -(function TestExtensibility() { - function f() {} - Object.preventExtensions(f); - assertFalse(Object.isExtensible(f)); - var m = %ToMethod(f, {}); - assertTrue(Object.isExtensible(m)); -}()); diff --git a/test/mjsunit/harmony/super.js b/test/mjsunit/harmony/super.js index 601addaa0..f7584702b 100644 --- a/test/mjsunit/harmony/super.js +++ b/test/mjsunit/harmony/super.js @@ -81,39 +81,6 @@ }()); -(function TestSuperNumericKeyedLoads() { - var x = 1; - var derivedDataProperty = 2; - var f = 3; - - function Base() { } - function fBase() { return "Base " + this.toString(); } - Base.prototype[f] = %ToMethod(fBase, Base.prototype); - Base.prototype[x] = 15; - Base.prototype.toString = function() { return "this is Base"; }; - - function Derived() { - this[derivedDataProperty] = "xxx"; - } - Derived.prototype = { - __proto__: Base.prototype, - toString() { return "this is Derived"; }, - 1: 27, - 3() { - assertEquals("Base this is Derived", super[f]()); - var a = super[x]; - assertEquals(15, a); - assertEquals(15, super[x]); - assertEquals(27, this[x]); - return "Derived"; - } - }; - - assertEquals("Base this is Base", new Base()[f]()); - assertEquals("Derived", new Derived()[f]()); -}()); - - (function TestSuperKeywordNonMethod() { 'use strict'; -- 2.34.1