Index: test/mjsunit/compiler/inline-accessors.js |
diff --git a/test/mjsunit/compiler/inline-accessors.js b/test/mjsunit/compiler/inline-accessors.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b4a37880763ae52f6afb7175dfe6de898b73a5ae |
--- /dev/null |
+++ b/test/mjsunit/compiler/inline-accessors.js |
@@ -0,0 +1,153 @@ |
+// 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. |
+ |
+// Flags: --allow-natives-syntax --inline-accessors |
+ |
+var accessorCallCount, setterValue, obj; |
+function Constr1() { } |
+function Constr2() { } |
+function Constr3() { } |
Michael Starzinger
2012/08/08 13:05:33
Can we move the constructors down, right before th
Sven Panne
2012/08/08 14:15:20
Done.
|
+ |
+// ----------------------------------------------------------------------------- |
+// Helpers for testing inlining of getters. |
+ |
+function TestInlinedGetter(context) { |
+ accessorCallCount = 0; |
+ |
+ assertEquals(1234, context()); |
+ assertEquals(1, accessorCallCount); |
+ |
+ assertEquals(1234, context()); |
+ assertEquals(2, accessorCallCount); |
+ |
+ %OptimizeFunctionOnNextCall(context); |
+ assertEquals(1234, context()); |
+ assertEquals(3, accessorCallCount); |
+ |
+ %DeoptimizeFunction(context); |
+ %ClearFunctionTypeFeedback(context); |
+} |
+ |
+ |
+function TestGetterInAllContexts(obj) { |
+ function value_context() { |
+ return obj.getterProperty; |
+ } |
+ TestInlinedGetter(value_context); |
+ |
+ function test_context() { |
+ if (!obj.getterProperty) { |
+ assertUnreachable("should not happen"); |
+ } |
+ return 1234; |
+ } |
+ TestInlinedGetter(test_context); |
+ |
+ function effect_context() { |
+ obj.getterProperty; |
+ return 1234; |
+ } |
+ TestInlinedGetter(effect_context); |
+} |
+ |
+// ----------------------------------------------------------------------------- |
+// Test getter in all contexts. |
+function getter1() { |
+ accessorCallCount++; |
+ return 1234; |
Michael Starzinger
2012/08/08 13:05:33
You might want to consider returning a global "get
Sven Panne
2012/08/08 14:15:20
As discussed offline, this will be done via an exp
|
+} |
+ |
+obj = Object.defineProperty(new Constr1(), "getterProperty", { get: getter1 }); |
+TestGetterInAllContexts(obj); |
+TestGetterInAllContexts(Object.create(obj)); |
Michael Starzinger
2012/08/08 13:05:33
Also test a getter that falls off the function end
Sven Panne
2012/08/08 14:15:20
Done.
|
+ |
+// ----------------------------------------------------------------------------- |
+// Helpers for testing inlining of setters. |
+ |
+function TestInlinedSetter(context) { |
+ accessorCallCount = 0; |
+ |
+ assertEquals(112, context(111)); |
+ assertEquals(114, setterValue); |
+ assertEquals(1, accessorCallCount); |
+ |
+ assertEquals(223, context(222)); |
+ assertEquals(225, setterValue); |
+ assertEquals(2, accessorCallCount); |
+ |
+ %OptimizeFunctionOnNextCall(context); |
+ assertEquals(334, context(333)); |
+ assertEquals(336, setterValue); |
+ assertEquals(3, accessorCallCount); |
+ |
+ %DeoptimizeFunction(context); |
+ %ClearFunctionTypeFeedback(context); |
+} |
+ |
+function TestSetterInAllContexts(obj) { |
+ function value_context(value) { |
+ return obj.setterProperty = value + 1; |
Michael Starzinger
2012/08/08 13:05:33
I wouldn't use an addition on the RHS, otherwise i
Sven Panne
2012/08/08 14:15:20
Done.
|
+ } |
+ TestInlinedSetter(value_context); |
+ |
+ function test_context(value) { |
+ if (!(obj.setterProperty = value + 1)) { |
+ assertUnreachable("should not happen"); |
+ } |
+ return value + 1; |
+ } |
+ TestInlinedSetter(test_context); |
+ |
+ function effect_context(value) { |
+ obj.setterProperty = value + 1; |
+ return value + 1; |
+ } |
+ TestInlinedSetter(effect_context); |
+} |
+ |
+// ----------------------------------------------------------------------------- |
+// Test setter returning nothing in all contexts. |
+function setter1(value) { |
+ accessorCallCount++; |
+ setterValue = value + 2; |
+} |
+ |
+obj = Object.defineProperty(new Constr2(), "setterProperty", { set: setter1 }); |
+TestSetterInAllContexts(obj); |
+TestSetterInAllContexts(Object.create(obj)); |
+ |
+// ----------------------------------------------------------------------------- |
+// Test setter returning something different than the RHS in all contexts. |
+function setter2(value) { |
+ accessorCallCount++; |
+ setterValue = value + 2; |
+ return value + 1000000; |
+} |
+ |
+obj = Object.defineProperty(new Constr3(), "setterProperty", { set: setter2 }); |
+TestSetterInAllContexts(obj); |
+TestSetterInAllContexts(Object.create(obj)); |
Michael Starzinger
2012/08/08 13:05:33
We also need tests for arguments mismatch of both
Sven Panne
2012/08/08 14:15:20
Still a TODO...
|