From f30b43ed95582c6b1e71f3fb52449cd93b5d9702 Mon Sep 17 00:00:00 2001 From: Hai Dang Date: Tue, 21 Aug 2018 12:05:08 +0200 Subject: [PATCH] Add bytecode generation tests for array spreads. Bug: v8:7973 Change-Id: I44ad457c3a103c36bd7b928cc64a056c1a1afc46 Reviewed-on: https://chromium-review.googlesource.com/1183102 Reviewed-by: Georg Neis Reviewed-by: Ross McIlroy Commit-Queue: Hai Dang Cr-Commit-Position: refs/heads/master@{#55257} --- .../ArrayLiterals.golden | 161 ++++++++++++++++++ .../interpreter/test-bytecode-generator.cc | 6 + 2 files changed, 167 insertions(+) diff --git a/test/cctest/interpreter/bytecode_expectations/ArrayLiterals.golden b/test/cctest/interpreter/bytecode_expectations/ArrayLiterals.golden index 9714926254..ae8d050914 100644 --- a/test/cctest/interpreter/bytecode_expectations/ArrayLiterals.golden +++ b/test/cctest/interpreter/bytecode_expectations/ArrayLiterals.golden @@ -117,3 +117,164 @@ constant pool: [ handlers: [ ] +--- +snippet: " + var a = [ 1, 2 ]; return [ ...a ]; +" +frame size: 8 +parameter count: 1 +bytecode array length: 86 +bytecodes: [ + /* 30 E> */ B(StackCheck), + /* 42 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(37), + B(Star), R(0), + /* 52 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(37), + B(Star), R(1), + B(LdaConstant), U8(2), + /* 64 S> */ B(Star), R(2), + B(LdaNamedProperty), R(0), U8(3), U8(7), + B(Star), R(7), + B(CallProperty0), R(7), R(0), U8(9), + B(Mov), R(0), R(6), + B(JumpIfJSReceiver), U8(7), + B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0), + B(Star), R(5), + B(LdaNamedProperty), R(5), U8(4), U8(11), + B(Star), R(4), + B(CallProperty0), R(4), R(5), U8(13), + B(Star), R(3), + B(JumpIfJSReceiver), U8(7), + B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(3), U8(1), + B(LdaNamedProperty), R(3), U8(5), U8(15), + B(JumpIfToBooleanTrue), U8(21), + B(LdaNamedProperty), R(3), U8(6), U8(17), + B(Star), R(3), + B(StaInArrayLiteral), R(1), R(2), U8(2), + B(Ldar), R(2), + B(Inc), U8(4), + B(Star), R(2), + B(JumpLoop), U8(35), I8(0), + B(Ldar), R(1), + /* 68 S> */ B(Return), +] +constant pool: [ + ARRAY_BOILERPLATE_DESCRIPTION_TYPE, + ARRAY_BOILERPLATE_DESCRIPTION_TYPE, + Smi [0], + SYMBOL_TYPE, + ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"], + ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"], + ONE_BYTE_INTERNALIZED_STRING_TYPE ["value"], +] +handlers: [ +] + +--- +snippet: " + var a = [ 1, 2 ]; return [ 0, ...a ]; +" +frame size: 8 +parameter count: 1 +bytecode array length: 86 +bytecodes: [ + /* 30 E> */ B(StackCheck), + /* 42 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(37), + B(Star), R(0), + /* 52 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(37), + B(Star), R(1), + B(LdaConstant), U8(2), + /* 67 S> */ B(Star), R(2), + B(LdaNamedProperty), R(0), U8(3), U8(7), + B(Star), R(7), + B(CallProperty0), R(7), R(0), U8(9), + B(Mov), R(0), R(6), + B(JumpIfJSReceiver), U8(7), + B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0), + B(Star), R(5), + B(LdaNamedProperty), R(5), U8(4), U8(11), + B(Star), R(4), + B(CallProperty0), R(4), R(5), U8(13), + B(Star), R(3), + B(JumpIfJSReceiver), U8(7), + B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(3), U8(1), + B(LdaNamedProperty), R(3), U8(5), U8(15), + B(JumpIfToBooleanTrue), U8(21), + B(LdaNamedProperty), R(3), U8(6), U8(17), + B(Star), R(3), + B(StaInArrayLiteral), R(1), R(2), U8(2), + B(Ldar), R(2), + B(Inc), U8(4), + B(Star), R(2), + B(JumpLoop), U8(35), I8(0), + B(Ldar), R(1), + /* 71 S> */ B(Return), +] +constant pool: [ + ARRAY_BOILERPLATE_DESCRIPTION_TYPE, + ARRAY_BOILERPLATE_DESCRIPTION_TYPE, + Smi [1], + SYMBOL_TYPE, + ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"], + ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"], + ONE_BYTE_INTERNALIZED_STRING_TYPE ["value"], +] +handlers: [ +] + +--- +snippet: " + var a = [ 1, 2 ]; return [ ...a, 3 ]; +" +frame size: 8 +parameter count: 1 +bytecode array length: 98 +bytecodes: [ + /* 30 E> */ B(StackCheck), + /* 42 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(37), + B(Star), R(0), + /* 52 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(37), + B(Star), R(1), + B(LdaConstant), U8(2), + /* 64 S> */ B(Star), R(2), + B(LdaNamedProperty), R(0), U8(3), U8(7), + B(Star), R(7), + B(CallProperty0), R(7), R(0), U8(9), + B(Mov), R(0), R(6), + B(JumpIfJSReceiver), U8(7), + B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0), + B(Star), R(5), + B(LdaNamedProperty), R(5), U8(4), U8(11), + B(Star), R(4), + B(CallProperty0), R(4), R(5), U8(13), + B(Star), R(3), + B(JumpIfJSReceiver), U8(7), + B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(3), U8(1), + B(LdaNamedProperty), R(3), U8(5), U8(15), + B(JumpIfToBooleanTrue), U8(21), + B(LdaNamedProperty), R(3), U8(6), U8(17), + B(Star), R(3), + B(StaInArrayLiteral), R(1), R(2), U8(2), + B(Ldar), R(2), + B(Inc), U8(4), + B(Star), R(2), + B(JumpLoop), U8(35), I8(0), + B(LdaSmi), I8(3), + B(StaInArrayLiteral), R(1), R(2), U8(2), + B(Ldar), R(2), + B(Inc), U8(4), + B(Star), R(2), + B(Ldar), R(1), + /* 71 S> */ B(Return), +] +constant pool: [ + ARRAY_BOILERPLATE_DESCRIPTION_TYPE, + ARRAY_BOILERPLATE_DESCRIPTION_TYPE, + Smi [0], + SYMBOL_TYPE, + ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"], + ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"], + ONE_BYTE_INTERNALIZED_STRING_TYPE ["value"], +] +handlers: [ +] + diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc index 8334c1dbee..9b5b17bef7 100644 --- a/test/cctest/interpreter/test-bytecode-generator.cc +++ b/test/cctest/interpreter/test-bytecode-generator.cc @@ -1437,6 +1437,12 @@ TEST(ArrayLiterals) { "return [ [ 1, 2 ], [ 3 ] ];\n", "var a = 1; return [ [ a, 2 ], [ a + 2 ] ];\n", + + "var a = [ 1, 2 ]; return [ ...a ];\n", + + "var a = [ 1, 2 ]; return [ 0, ...a ];\n", + + "var a = [ 1, 2 ]; return [ ...a, 3 ];\n", }; CHECK(CompareTexts(BuildActual(printer, snippets),