Index: test/mjsunit/harmony/toMethod.js |
diff --git a/test/mjsunit/compiler/property-static.js b/test/mjsunit/harmony/toMethod.js |
similarity index 53% |
copy from test/mjsunit/compiler/property-static.js |
copy to test/mjsunit/harmony/toMethod.js |
index 07021340cd7aa94440638f925eeed921ee78c9c7..b1abb068430a4b3a854e85cb62a261f10294a6d1 100644 |
--- a/test/mjsunit/compiler/property-static.js |
+++ b/test/mjsunit/harmony/toMethod.js |
@@ -24,46 +24,81 @@ |
// 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. |
+// |
+// Flags: --harmony-classes --allow-natives-syntax |
-// Flags: --allow-natives-syntax |
-// Test usage of static type information for loads that would otherwise |
-// turn into polymorphic or generic loads. |
+(function () { |
+ function f(x) { |
+ var a = [0, 1, 2] |
+ return a[x]; |
+ } |
-// Prepare a highly polymorphic load to be used by all tests. |
-Object.prototype.load = function() { return this.property; }; |
-Object.prototype.load.call({ A:0, property:10 }); |
-Object.prototype.load.call({ A:0, B:0, property:11 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, property:12 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, property:13 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, property:14 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, F:0, property:15 }); |
+ function ClassD() { } |
-// Test for object literals. |
-(function() { |
+ assertEquals(1, f(1)); |
+ var g = f.toMethod(ClassD.prototype); |
+ assertEquals(1, g(1)); |
+ assertEquals(undefined, f[%HomeObjectSymbol()]); |
+ assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]); |
+}()); |
+ |
+ |
+(function () { |
function f(x) { |
- var object = { property:x }; |
- return object.load(); |
+ return function g(y) { x++; return x + y; }; |
} |
- assertSame(1, f(1)); |
- assertSame(2, f(2)); |
- %OptimizeFunctionOnNextCall(f); |
- assertSame(3, f(3)); |
-})(); |
+ function Base() {} |
+ function Derived() { } |
+ Derived.prototype = Object.create(Base.prototype); |
+ |
+ var q = f(0); |
+ assertEquals(2, q(1)); |
+ assertEquals(3, q(1)); |
+ var g = q.toMethod(Derived.prototype); |
+ assertFalse(g === q); |
+ assertEquals(4, g(1)); |
+ assertEquals(5, q(1)); |
+}()); |
-// Test for inlined constructors. |
(function() { |
- function c(x) { |
- this.property = x; |
- } |
- function f(x) { |
- var object = new c(x); |
- return object.load(); |
+ var sFun = Function.prototype.toMethod; |
+ assertThrows(function() { sFun.call({}); }, TypeError); |
+ function f(){}; |
+ assertThrows(function() { f.toMethod(1); }, TypeError); |
+}()); |
+ |
+(function() { |
+ var o = {}; |
+ var o1 = {}; |
+ function f() { } |
+ |
+ function g() { } |
+ |
+ var fMeth = f.toMethod(o); |
+ assertEquals(o, fMeth[%HomeObjectSymbol()]); |
+ g.__proto__ = fMeth; |
+ assertEquals(undefined, g[%HomeObjectSymbol()]); |
+ var gMeth = g.toMethod(o1); |
+ assertEquals(fMeth, gMeth.__proto__); |
+ assertEquals(o1, gMeth[%HomeObjectSymbol()]); |
+}()); |
+ |
+(function() { |
+ var o = {}; |
+ var p = {}; |
+ |
+ |
+ function f(x, y, z) { |
+ assertEquals(o, this); |
+ assertEquals(1, x); |
+ assertEquals(2, y); |
+ assertEquals(3, z); |
} |
- assertSame(1, f(1)); |
- assertSame(2, f(2)); |
- %OptimizeFunctionOnNextCall(f); |
- assertSame(3, f(3)); |
-})(); |
+ var fBound = f.bind(o, 1, 2, 3); |
+ var fMeth = fBound.toMethod(p); |
+ fMeth(); |
+ fMeth.call(p); |
+}()); |