| OLD | NEW |
| 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 Loading... |
| 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, |
| 86 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 87 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 88 CompileRun("function f(){ ++a; ++a()[b]; }"); |
| 89 CHECK_EQ(0, |
| 90 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 91 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 92 CompileRun("function f(){ 'use strict'; a = 0; a()[b] = 0; }"); |
| 93 CHECK_EQ(0, |
| 94 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 95 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 96 CompileRun("function f(){ 'use strict'; ++a; ++a()[b]; }"); |
| 97 CHECK_EQ(0, |
| 98 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 99 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 100 |
| 101 // AssignmentExpressions whose LHS is a call increment appropriate counters |
| 102 CompileRun("function f(){ a() = 0; }"); |
| 103 CHECK_EQ(1, |
| 104 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 105 CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 106 CompileRun("function f(){ 'use strict'; a() = 0; }"); |
| 107 CHECK_EQ(1, |
| 108 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 109 CHECK_EQ(1, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 110 |
| 111 // UpdateExpressions whose LHS is a call increment appropriate counters |
| 112 CompileRun("function f(){ ++a(); }"); |
| 113 CHECK_EQ(2, |
| 114 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 115 CHECK_EQ(1, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 116 CompileRun("function f(){ 'use strict'; ++a(); }"); |
| 117 CHECK_EQ(2, |
| 118 use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInNonstrict]); |
| 119 CHECK_EQ(2, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]); |
| 120 } |
| OLD | NEW |