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

Side by Side Diff: test/cctest/test-usecounters.cc

Issue 2599253002: [counters] Add UseCounters for 'f() = 0' syntax (Closed)
Patch Set: fix test Created 3 years, 12 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
« no previous file with comments | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 "var a = {};" 64 "var a = {};"
65 "Object.defineProperty(a, 'b', { value: 0, configurable: false });" 65 "Object.defineProperty(a, 'b', { value: 0, configurable: false });"
66 "a.__defineGetter__('b', ()=>{});"); 66 "a.__defineGetter__('b', ()=>{});");
67 CHECK_EQ(1, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); 67 CHECK_EQ(1, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]);
68 CompileRun( 68 CompileRun(
69 "var a = {};" 69 "var a = {};"
70 "Object.defineProperty(a, 'b', { value: 0, configurable: false });" 70 "Object.defineProperty(a, 'b', { value: 0, configurable: false });"
71 "a.__defineSetter__('b', ()=>{});"); 71 "a.__defineSetter__('b', ()=>{});");
72 CHECK_EQ(2, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); 72 CHECK_EQ(2, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]);
73 } 73 }
74
75 TEST(AssigmentExpressionLHSIsCall) {
76 v8::Isolate* isolate = CcTest::isolate();
77 v8::HandleScope scope(isolate);
78 LocalContext env;
79 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
80 global_use_counts = use_counts;
81 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
82
83 // AssignmentExpressions whose LHS is not a call do not increment counters
84 CompileRun("function f(){ a = 0; a()[b] = 0; }");
85 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
86 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
87 CompileRun("function f(){ ++a; ++a()[b]; }");
88 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
89 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
90 CompileRun("function f(){ 'use strict'; a = 0; a()[b] = 0; }");
91 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
92 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
93 CompileRun("function f(){ 'use strict'; ++a; ++a()[b]; }");
94 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
95 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
96
97 // AssignmentExpressions whose LHS is a call increment appropriate counters
98 CompileRun("function f(){ a() = 0; }");
99 CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
100 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
101 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy] = 0;
102 CompileRun("function f(){ 'use strict'; a() = 0; }");
103 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
104 CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
105 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict] = 0;
106
107 // UpdateExpressions whose LHS is a call increment appropriate counters
108 CompileRun("function f(){ ++a(); }");
109 CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
110 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
111 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy] = 0;
112 CompileRun("function f(){ 'use strict'; ++a(); }");
113 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
114 CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
115 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict] = 0;
116 }
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698