Skip to content

Commit 5a818a8

Browse files
committed
Add literal property to the byte code list.
Initalizing a property with a constant is frequent in object initializers. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent 9625fb8 commit 5a818a8

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

jerry-core/api/jerry-snapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct
4141
/**
4242
* Jerry snapshot format version.
4343
*/
44-
#define JERRY_SNAPSHOT_VERSION (13u)
44+
#define JERRY_SNAPSHOT_VERSION (14u)
4545

4646
/**
4747
* Snapshot configuration flags.

jerry-core/parser/js/byte-code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@
317317
VM_OC_RET) \
318318
CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
319319
VM_OC_RET | VM_OC_GET_LITERAL) \
320+
CBC_OPCODE (CBC_SET_LITERAL_PROPERTY, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
321+
VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \
320322
CBC_OPCODE (CBC_BREAKPOINT_ENABLED, CBC_NO_FLAG, 0, \
321323
VM_OC_BREAKPOINT_ENABLED) \
322324
CBC_OPCODE (CBC_BREAKPOINT_DISABLED, CBC_NO_FLAG, 0, \

jerry-core/parser/js/js-parser-expr.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,15 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
430430
lexer_next_token (context_p);
431431
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);
432432

433-
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index);
433+
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
434+
{
435+
context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY;
436+
context_p->last_cbc.value = literal_index;
437+
}
438+
else
439+
{
440+
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index);
441+
}
434442
}
435443

436444
if (context_p->token.type == LEXER_RIGHT_BRACE)

tests/unit-core/test-snapshot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ main (void)
216216
/* Check the snapshot data. Unused bytes should be filled with zeroes */
217217
const uint8_t expected_data[] =
218218
{
219-
0x4A, 0x52, 0x52, 0x59, 0x0D, 0x00, 0x00, 0x00,
219+
0x4A, 0x52, 0x52, 0x59, 0x0E, 0x00, 0x00, 0x00,
220220
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
221221
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
222222
0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,

0 commit comments

Comments
 (0)