Chromium Code Reviews| Index: test/mjsunit/compiler/inline-accessors.js |
| diff --git a/test/mjsunit/compiler/inline-accessors.js b/test/mjsunit/compiler/inline-accessors.js |
| index 41302c12388e874675d7f9b571d8bc192f17fdcc..cfe9d23bc6278ab8a978fbf7975907cb09670452 100644 |
| --- a/test/mjsunit/compiler/inline-accessors.js |
| +++ b/test/mjsunit/compiler/inline-accessors.js |
| @@ -25,52 +25,67 @@ |
| // (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 |
| +// Flags: --allow-natives-syntax --inline-accessors --max-opt-count=100 |
| var accessorCallCount, setterArgument, setterValue, obj, forceDeopt; |
| // ----------------------------------------------------------------------------- |
| // Helpers for testing inlining of getters. |
| -function TestInlinedGetter(context, expected) { |
| - forceDeopt = 0; |
| +function TestInlinedGetter(context, obj, expected) { |
| + forceDeopt = { deopt: 0 }; |
| accessorCallCount = 0; |
| - assertEquals(expected, context()); |
| + assertEquals(expected, context(obj)); |
| assertEquals(1, accessorCallCount); |
| - assertEquals(expected, context()); |
| + assertEquals(expected, context(obj)); |
| assertEquals(2, accessorCallCount); |
| %OptimizeFunctionOnNextCall(context); |
| - assertEquals(expected, context()); |
| + assertEquals(expected, context(obj)); |
| assertEquals(3, accessorCallCount); |
| - %DeoptimizeFunction(context); |
| - %ClearFunctionTypeFeedback(context); |
| + forceDeopt = { /* empty*/ }; |
| + assertEquals(expected, context(obj)); |
| + assertEquals(4, accessorCallCount); |
| } |
| -function TestGetterInAllContexts(obj, expected) { |
| - function value_context() { |
| - return obj.getterProperty; |
| - } |
| - TestInlinedGetter(value_context, expected); |
| - |
| - function test_context() { |
| - if (obj.getterProperty) { |
| - return 111; |
| - } else { |
| - return 222; |
| - } |
| +function value_context_for_getter(obj) { |
| + return obj.getterProperty; |
| +} |
| + |
| +function test_context_for_getter(obj) { |
| + if (obj.getterProperty) { |
| + return 111; |
| + } else { |
| + return 222; |
| } |
| - TestInlinedGetter(test_context, expected ? 111 : 222); |
| +} |
| - function effect_context() { |
| - obj.getterProperty; |
| - return 5678; |
| +function effect_context_for_getter(obj) { |
| + obj.getterProperty; |
| + return 5678; |
| +} |
| + |
| +function TryGetter(context, getter, obj, expected, expectException) { |
| + try { |
| + TestInlinedGetter(context, obj, expected); |
|
Michael Starzinger
2012/08/17 10:03:51
Can we add assertFalse(expectException) after the
Sven Panne
2012/08/17 11:33:49
Done.
|
| + } catch (exception) { |
| + assertTrue(expectException); |
| + assertEquals(7, exception.stack.split('\n').length); |
| } |
| - TestInlinedGetter(effect_context, 5678); |
| + %DeoptimizeFunction(context); |
| + %ClearFunctionTypeFeedback(context); |
| + %ClearFunctionTypeFeedback(getter); |
| +} |
| + |
| +function TestGetterInAllContexts(getter, obj, expected, expectException) { |
| + TryGetter(value_context_for_getter, getter, obj, expected, expectException); |
| + TryGetter(test_context_for_getter, getter, obj, expected ? 111 : 222, |
| + expectException); |
| + TryGetter(effect_context_for_getter, getter, obj, 5678, expectException); |
| } |
| // ----------------------------------------------------------------------------- |
| @@ -79,15 +94,15 @@ function TestGetterInAllContexts(obj, expected) { |
| function getter1() { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| return 1234; |
| } |
| function ConstrG1() { } |
| obj = Object.defineProperty(new ConstrG1(), "getterProperty", { get: getter1 }); |
| -TestGetterInAllContexts(obj, 1234); |
| +TestGetterInAllContexts(getter1, obj, 1234, false); |
| obj = Object.create(obj); |
| -TestGetterInAllContexts(obj, 1234); |
| +TestGetterInAllContexts(getter1, obj, 1234, false); |
| // ----------------------------------------------------------------------------- |
| // Test getter returning false in all contexts. |
| @@ -95,15 +110,15 @@ TestGetterInAllContexts(obj, 1234); |
| function getter2() { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| return false; |
| } |
| function ConstrG2() { } |
| obj = Object.defineProperty(new ConstrG2(), "getterProperty", { get: getter2 }); |
| -TestGetterInAllContexts(obj, false); |
| +TestGetterInAllContexts(getter2, obj, false, false); |
| obj = Object.create(obj); |
| -TestGetterInAllContexts(obj, false); |
| +TestGetterInAllContexts(getter2, obj, false, false); |
| // ----------------------------------------------------------------------------- |
| // Test getter without a return in all contexts. |
| @@ -111,14 +126,14 @@ TestGetterInAllContexts(obj, false); |
| function getter3() { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| } |
| function ConstrG3() { } |
| obj = Object.defineProperty(new ConstrG3(), "getterProperty", { get: getter3 }); |
| -TestGetterInAllContexts(obj, undefined); |
| +TestGetterInAllContexts(getter3, obj, undefined, false); |
| obj = Object.create(obj); |
| -TestGetterInAllContexts(obj, undefined); |
| +TestGetterInAllContexts(getter3, obj, undefined, false); |
| // ----------------------------------------------------------------------------- |
| // Test getter with too many arguments without a return in all contexts. |
| @@ -127,14 +142,14 @@ function getter4(a) { |
| assertSame(obj, this); |
| assertEquals(undefined, a); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| } |
| function ConstrG4() { } |
| obj = Object.defineProperty(new ConstrG4(), "getterProperty", { get: getter4 }); |
| -TestGetterInAllContexts(obj, undefined); |
| +TestGetterInAllContexts(getter4, obj, undefined); |
|
Michael Starzinger
2012/08/17 10:03:51
Can we add the fourth expectException argument her
|
| obj = Object.create(obj); |
| -TestGetterInAllContexts(obj, undefined); |
| +TestGetterInAllContexts(getter4, obj, undefined); |
|
Michael Starzinger
2012/08/17 10:03:51
Likewise.
|
| // ----------------------------------------------------------------------------- |
| // Test getter with too many arguments with a return in all contexts. |
| @@ -143,62 +158,94 @@ function getter5(a) { |
| assertSame(obj, this); |
| assertEquals(undefined, a); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| return 9876; |
| } |
| function ConstrG5() { } |
| obj = Object.defineProperty(new ConstrG5(), "getterProperty", { get: getter5 }); |
| -TestGetterInAllContexts(obj, 9876); |
| +TestGetterInAllContexts(getter5, obj, 9876, false); |
| +obj = Object.create(obj); |
| +TestGetterInAllContexts(getter5, obj, 9876, false); |
| + |
| +// ----------------------------------------------------------------------------- |
| +// Test getter which throws from optimized code. |
| + |
| +function getter6() { |
| + assertSame(obj, this); |
| + accessorCallCount++; |
| + forceDeopt.deopt; |
| + if (accessorCallCount == 4) { 123 in null; } |
| + return 13579; |
| +} |
| + |
| +function ConstrG6() { } |
| +obj = Object.defineProperty(new ConstrG6(), "getterProperty", { get: getter6 }); |
| +TestGetterInAllContexts(getter6, obj, 13579, true); |
| obj = Object.create(obj); |
| -TestGetterInAllContexts(obj, 9876); |
| +TestGetterInAllContexts(getter6, obj, 13579, true); |
| // ----------------------------------------------------------------------------- |
| // Helpers for testing inlining of setters. |
| -function TestInlinedSetter(context, value, expected) { |
| - forceDeopt = 0; |
| +function TestInlinedSetter(context, obj, value, expected) { |
| + forceDeopt = { deopt: 0 }; |
| accessorCallCount = 0; |
| setterArgument = value; |
| - assertEquals(expected, context(value)); |
| + assertEquals(expected, context(obj, value)); |
| assertEquals(value, setterValue); |
| assertEquals(1, accessorCallCount); |
| - assertEquals(expected, context(value)); |
| + assertEquals(expected, context(obj, value)); |
| assertEquals(value, setterValue); |
| assertEquals(2, accessorCallCount); |
| %OptimizeFunctionOnNextCall(context); |
| - assertEquals(expected, context(value)); |
| + assertEquals(expected, context(obj, value)); |
| assertEquals(value, setterValue); |
| assertEquals(3, accessorCallCount); |
| - %DeoptimizeFunction(context); |
| - %ClearFunctionTypeFeedback(context); |
| + forceDeopt = { /* empty*/ }; |
| + assertEquals(expected, context(obj, value)); |
| + assertEquals(value, setterValue); |
| + assertEquals(4, accessorCallCount); |
| } |
| -function TestSetterInAllContexts(obj) { |
| - function value_context(value) { |
| - return obj.setterProperty = value; |
| - } |
| - TestInlinedSetter(value_context, 111, 111); |
| - |
| - function test_context(value) { |
| - if (obj.setterProperty = value) { |
| - return 333; |
| - } else { |
| - return 444; |
| - } |
| +function value_context_for_setter(obj, value) { |
| + return obj.setterProperty = value; |
| +} |
| + |
| +function test_context_for_setter(obj, value) { |
| + if (obj.setterProperty = value) { |
| + return 333; |
| + } else { |
| + return 444; |
| } |
| - TestInlinedSetter(test_context, true, 333); |
| - TestInlinedSetter(test_context, false, 444); |
| +} |
| + |
| +function effect_context_for_setter(obj, value) { |
| + obj.setterProperty = value; |
| + return 666; |
| +} |
| - function effect_context(value) { |
| - obj.setterProperty = value; |
| - return 666; |
| +function TrySetter(context, setter, obj, expectException, value, expected) { |
| + try { |
| + TestInlinedSetter(context, obj, value, expected); |
|
Michael Starzinger
2012/08/17 10:03:51
Likewise.
Sven Panne
2012/08/17 11:33:49
Done.
|
| + } catch (exception) { |
| + assertTrue(expectException); |
| + assertEquals(7, exception.stack.split('\n').length); |
| } |
| - TestInlinedSetter(effect_context, 555, 666); |
| + %DeoptimizeFunction(context); |
| + %ClearFunctionTypeFeedback(context); |
| + %ClearFunctionTypeFeedback(setter); |
| +} |
| + |
| +function TestSetterInAllContexts(setter, obj, expectException) { |
| + TrySetter(value_context_for_setter, setter, obj, expectException, 111, 111); |
| + TrySetter(test_context_for_setter, setter, obj, expectException, true, 333); |
| + TrySetter(test_context_for_setter, setter, obj, expectException, false, 444); |
| + TrySetter(effect_context_for_setter, setter, obj, expectException, 555, 666); |
| } |
| // ----------------------------------------------------------------------------- |
| @@ -207,15 +254,15 @@ function TestSetterInAllContexts(obj) { |
| function setter1(value) { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| setterValue = value; |
| } |
| function ConstrS1() { } |
| obj = Object.defineProperty(new ConstrS1(), "setterProperty", { set: setter1 }); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter1, obj, false); |
| obj = Object.create(obj); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter1, obj, false); |
| // ----------------------------------------------------------------------------- |
| // Test setter returning something different than the RHS in all contexts. |
| @@ -223,16 +270,16 @@ TestSetterInAllContexts(obj); |
| function setter2(value) { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| setterValue = value; |
| return 1000000; |
| } |
| function ConstrS2() { } |
| obj = Object.defineProperty(new ConstrS2(), "setterProperty", { set: setter2 }); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter2, obj, false); |
| obj = Object.create(obj); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter2, obj, false); |
| // ----------------------------------------------------------------------------- |
| // Test setter with too few arguments without a return in all contexts. |
| @@ -240,15 +287,15 @@ TestSetterInAllContexts(obj); |
| function setter3() { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| setterValue = setterArgument; |
| } |
| function ConstrS3() { } |
| obj = Object.defineProperty(new ConstrS3(), "setterProperty", { set: setter3 }); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter3, obj, false); |
| obj = Object.create(obj); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter3, obj, false); |
| // ----------------------------------------------------------------------------- |
| // Test setter with too few arguments with a return in all contexts. |
| @@ -256,16 +303,16 @@ TestSetterInAllContexts(obj); |
| function setter4() { |
| assertSame(obj, this); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| setterValue = setterArgument; |
| return 2000000; |
| } |
| function ConstrS4() { } |
| obj = Object.defineProperty(new ConstrS4(), "setterProperty", { set: setter4 }); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter4, obj, false); |
| obj = Object.create(obj); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter4, obj, false); |
| // ----------------------------------------------------------------------------- |
| // Test setter with too many arguments without a return in all contexts. |
| @@ -274,15 +321,15 @@ function setter5(value, foo) { |
| assertSame(obj, this); |
| assertEquals(undefined, foo); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| setterValue = value; |
| } |
| function ConstrS5() { } |
| obj = Object.defineProperty(new ConstrS5(), "setterProperty", { set: setter5 }); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter5, obj, false); |
| obj = Object.create(obj); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter5, obj, false); |
| // ----------------------------------------------------------------------------- |
| // Test setter with too many arguments with a return in all contexts. |
| @@ -291,13 +338,29 @@ function setter6(value, foo) { |
| assertSame(obj, this); |
| assertEquals(undefined, foo); |
| accessorCallCount++; |
| - forceDeopt + 1; |
| + forceDeopt.deopt; |
| setterValue = value; |
| return 3000000; |
| } |
| function ConstrS6() { } |
| obj = Object.defineProperty(new ConstrS6(), "setterProperty", { set: setter6 }); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter6, obj, false); |
| +obj = Object.create(obj); |
| +TestSetterInAllContexts(setter6, obj, false); |
| + |
| +// ----------------------------------------------------------------------------- |
| +// Test setter which throws from optimized code. |
| + |
| +function setter7(value) { |
| + accessorCallCount++; |
| + forceDeopt.deopt; |
| + if (accessorCallCount == 4) { 123 in null; } |
| + setterValue = value; |
| +} |
| + |
| +function ConstrS7() { } |
| +obj = Object.defineProperty(new ConstrS7(), "setterProperty", { set: setter7 }); |
| +TestSetterInAllContexts(setter7, obj, true); |
| obj = Object.create(obj); |
| -TestSetterInAllContexts(obj); |
| +TestSetterInAllContexts(setter7, obj, true); |