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: merge Created 6 years, 3 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
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/runtime-gen/functionisconcisemethod.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2.0() {}
66 };
67 var f = object.method;
68 assertEquals('method', f.name);
69 var g = object[1];
70 assertEquals('1', g.name);
71
72 var h = object[2];
73 assertEquals('2', h.name);
74 })();
75
76
77 (function TestNoBinding() {
78 var method = 'local';
79 var calls = 0;
80 var object = {
81 method() {
82 calls++;
83 assertEquals('local', method);
84 }
85 };
86 object.method();
87 assertEquals(1, calls);
88 })();
89
90
91 (function TestNoPrototype() {
92 var object = {
93 method() {
94 return 42;
95 }
96 };
97 var f = object.method;
98 assertFalse(f.hasOwnProperty('prototype'));
99 assertEquals(undefined, f.prototype);
100
101 f.prototype = 42;
102 assertEquals(42, f.prototype);
103 })();
104
105
106 (function TestToString() {
107 var object = {
108 method() { 42; }
109 };
110 assertEquals('method() { 42; }', object.method.toString());
111 })();
112
113
114 (function TestOptimized() {
115 var object = {
116 method() { return 42; }
117 };
118 assertEquals(42, object.method());
119 assertEquals(42, object.method());
120 %OptimizeFunctionOnNextCall(object.method);
121 assertEquals(42, object.method());
122 assertFalse(object.method.hasOwnProperty('prototype'));
123 })();
OLDNEW
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/runtime-gen/functionisconcisemethod.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698