Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/harmony/object-literals-method.js

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add strict formal param checking Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-object-literals --allow-natives-syntax
6
7
8 (function TestDescriptor() {
9 var object = {
10 method() {
11 return 42;
12 }
13 };
14 assertEquals(42, object.method());
15 })();
16
17
18 (function TestDescriptor() {
19 var object = {
20 method() {
21 return 42;
22 }
23 };
24
25 var desc = Object.getOwnPropertyDescriptor(object, 'method');
26 assertTrue(desc.enumerable);
27 assertTrue(desc.configurable);
28 assertTrue(desc.writable);
29 assertEquals('function', typeof desc.value);
30
31 assertEquals(42, desc.value());
32 })();
33
34
35 (function TestProto() {
36 var object = {
37 method() {
38 return 42;
39 }
40 };
41
42 assertEquals(Function.prototype, Object.getPrototypeOf(object.method));
43 })();
44
45
46 (function TestNotConstructable() {
47 var object = {
48 method() {
49 return 42;
50 }
51 };
52
53 assertThrows(function() {
54 new object.method;
55 });
56 })();
57
58
59 (function TestFunctionName() {
60 var object = {
61 method() {
62 return 42;
63 },
64 1() {},
65 // https://code.google.com/p/v8/issues/detail?id=3507
66 // 2.0() {}
67 };
68 var f = object.method;
69 assertEquals('method', f.name);
70 var g = object[1];
71 assertEquals('1', g.name);
72
73 // https://code.google.com/p/v8/issues/detail?id=3507
74 // var h = object[2];
75 // assertEquals('2', h.name);
76 })();
77
78
79 (function TestNoBinding() {
80 var method = 'local';
81 var calls = 0;
82 var object = {
83 method() {
84 calls++;
85 assertEquals('local', method);
86 }
87 };
88 object.method();
89 assertEquals(1, calls);
90 })();
91
92
93 (function TestNoPrototype() {
94 var object = {
95 method() {
96 return 42;
97 }
98 };
99 var f = object.method;
100 assertFalse(f.hasOwnProperty('prototype'));
101 assertEquals(undefined, f.prototype);
102
103 f.prototype = 42;
104 assertEquals(42, f.prototype);
105 })();
106
107
108 (function TestToString() {
109 var object = {
110 method() { 42; }
111 };
112 assertEquals('method() { 42; }', object.method.toString());
113 })();
114
115
116 (function TestOptimized() {
117 var object = {
118 method() { return 42; }
119 };
120 assertEquals(42, object.method());
121 assertEquals(42, object.method());
122 %OptimizeFunctionOnNextCall(object.method);
123 assertEquals(42, object.method());
124 assertFalse(object.method.hasOwnProperty('prototype'));
125 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698