Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // 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.
 
 | |
| 27 | |
| 28 #include "src/v8.h" | |
| 29 | |
| 30 #include "test/cctest/cctest.h" | |
| 31 | |
| 32 namespace { | |
| 33 | |
| 34 int* global_use_counts = NULL; | |
| 35 | |
| 36 void MockUseCounterCallback(v8::Isolate* isolate, | |
| 37 v8::Isolate::UseCounterFeature feature) { | |
| 38 ++global_use_counts[feature]; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 TEST(DefineGetterSetterThrowUseCount) { | |
| 43 v8::Isolate* isolate = CcTest::isolate(); | |
| 44 v8::HandleScope scope(isolate); | |
| 45 LocalContext env; | |
| 46 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | |
| 47 global_use_counts = use_counts; | |
| 48 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | |
| 49 | |
| 50 // __defineGetter__ and __defineSetter__ do not increment | |
| 51 // kDefineGetterOrSetterWouldThrow on success | |
| 52 CompileRun( | |
| 53 "var a = {};" | |
| 54 "Object.defineProperty(a, 'b', { value: 0, configurable: true });" | |
| 55 "a.__defineGetter__('b', ()=>{});"); | |
| 56 CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); | |
| 57 CompileRun( | |
| 58 "var a = {};" | |
| 59 "Object.defineProperty(a, 'b', { value: 0, configurable: true });" | |
| 60 "a.__defineSetter__('b', ()=>{});"); | |
| 61 CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); | |
| 62 | |
| 63 // __defineGetter__ and __defineSetter__ do not increment | |
| 64 // kDefineGetterOrSetterWouldThrow on other errors | |
| 65 v8::Local<v8::Value> resultProxyThrow = CompileRun( | |
| 66 "var exception;" | |
| 67 "try {" | |
| 68 "var a = new Proxy({}, { defineProperty: ()=>{throw new Error;} });" | |
| 69 "a.__defineGetter__('b', ()=>{});" | |
| 70 "} catch (e) { exception = e; }" | |
| 71 "exception"); | |
| 72 CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); | |
| 73 CHECK(resultProxyThrow->IsObject()); | |
| 74 resultProxyThrow = CompileRun( | |
| 75 "var exception;" | |
| 76 "try {" | |
| 77 "var a = new Proxy({}, { defineProperty: ()=>{throw new Error;} });" | |
| 78 "a.__defineSetter__('b', ()=>{});" | |
| 79 "} catch (e) { exception = e; }" | |
| 80 "exception"); | |
| 81 CHECK_EQ(0, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); | |
| 82 CHECK(resultProxyThrow->IsObject()); | |
| 83 | |
| 84 // __defineGetter__ and __defineSetter__ increment | |
| 85 // kDefineGetterOrSetterWouldThrow when they would throw per spec (B.2.2.2) | |
| 86 CompileRun( | |
| 87 "var a = {};" | |
| 88 "Object.defineProperty(a, 'b', { value: 0, configurable: false });" | |
| 89 "a.__defineGetter__('b', ()=>{});"); | |
| 90 CHECK_EQ(1, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); | |
| 91 CompileRun( | |
| 92 "var a = {};" | |
| 93 "Object.defineProperty(a, 'b', { value: 0, configurable: false });" | |
| 94 "a.__defineSetter__('b', ()=>{});"); | |
| 95 CHECK_EQ(2, use_counts[v8::Isolate::kDefineGetterOrSetterWouldThrow]); | |
| 96 } | |
| OLD | NEW |