Index: test/cctest/test-usecounters.cc |
diff --git a/test/cctest/test-usecounters.cc b/test/cctest/test-usecounters.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9363ecc2587c0f95c681a1728bd6da928da95a7d |
--- /dev/null |
+++ b/test/cctest/test-usecounters.cc |
@@ -0,0 +1,96 @@ |
+// Copyright 2012 the V8 project authors. All rights reserved. |
+// Redistribution and use in source and binary forms, with or without |
+// modification, are permitted provided that the following conditions are |
+// met: |
+// |
+// * Redistributions of source code must retain the above copyright |
+// notice, this list of conditions and the following disclaimer. |
+// * Redistributions in binary form must reproduce the above |
+// copyright notice, this list of conditions and the following |
+// disclaimer in the documentation and/or other materials provided |
+// with the distribution. |
+// * Neither the name of Google Inc. nor the names of its |
+// contributors may be used to endorse or promote products derived |
+// from this software without specific prior written permission. |
+// |
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// 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. |
Dan Ehrenberg
2016/06/21 00:04:49
For new code, use an abbreviated copyright notice,
bakkot
2016/06/21 00:48:34
Addressed in new patchset.
|
+ |
+#include "src/v8.h" |
+ |
+#include "test/cctest/cctest.h" |
+ |
+namespace { |
+ |
+int* global_use_counts = NULL; |
+ |
+void MockUseCounterCallback(v8::Isolate* isolate, |
+ v8::Isolate::UseCounterFeature feature) { |
+ ++global_use_counts[feature]; |
+} |
+} |
+ |
+TEST(DefineGetterSetterThrowUseCount) { |
+ v8::Isolate* isolate = CcTest::isolate(); |
+ v8::HandleScope scope(isolate); |
+ LocalContext env; |
+ int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
+ global_use_counts = use_counts; |
+ CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
+ |
+ // __defineGetter__ and __defineSetter__ do not increment |
+ // kDefineGetterOrSetterWouldThrow on success |
+ CompileRun( |
+ "var a = {};" |
+ "Object.defineProperty(a, 'b', { value: 0, configurable: true });" |
+ "a.__defineGetter__('b', ()=>{});"); |
+ CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); |
+ CompileRun( |
+ "var a = {};" |
+ "Object.defineProperty(a, 'b', { value: 0, configurable: true });" |
+ "a.__defineSetter__('b', ()=>{});"); |
+ CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); |
+ |
+ // __defineGetter__ and __defineSetter__ do not increment |
+ // kDefineGetterOrSetterWouldThrow on other errors |
+ v8::Local<v8::Value> resultProxyThrow = CompileRun( |
+ "var exception;" |
+ "try {" |
+ "var a = new Proxy({}, { defineProperty: ()=>{throw new Error;} });" |
+ "a.__defineGetter__('b', ()=>{});" |
+ "} catch (e) { exception = e; }" |
+ "exception"); |
+ CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); |
+ CHECK(resultProxyThrow->IsObject()); |
+ resultProxyThrow = CompileRun( |
+ "var exception;" |
+ "try {" |
+ "var a = new Proxy({}, { defineProperty: ()=>{throw new Error;} });" |
+ "a.__defineSetter__('b', ()=>{});" |
+ "} catch (e) { exception = e; }" |
+ "exception"); |
+ CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); |
+ CHECK(resultProxyThrow->IsObject()); |
+ |
+ // __defineGetter__ and __defineSetter__ increment |
+ // kDefineGetterOrSetterWouldThrow when they would throw per spec (B.2.2.2) |
+ CompileRun( |
+ "var a = {};" |
+ "Object.defineProperty(a, 'b', { value: 0, configurable: false });" |
+ "a.__defineGetter__('b', ()=>{});"); |
+ CHECK_EQ(1, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); |
+ CompileRun( |
+ "var a = {};" |
+ "Object.defineProperty(a, 'b', { value: 0, configurable: false });" |
+ "a.__defineSetter__('b', ()=>{});"); |
+ CHECK_EQ(2, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); |
+} |