From 0a9e5a00405fb2383c89f2342cb4581b5b2cd366 Mon Sep 17 00:00:00 2001 From: Eric Faust Date: Tue, 2 Oct 2018 01:16:51 -0700 Subject: [PATCH] Bug 1494930 - Part 2: Correctly generate JSOP_FUNCALL and JSOP_FUNAPPLY. (r=arai) --HG-- extra : rebase_source : 3afd22c29202c2f8dbe6f491ec33c038afe113e3 --- js/src/frontend/BinSource-auto.cpp | 12 ++++++++++++ js/src/frontend/BinSource.yaml | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/js/src/frontend/BinSource-auto.cpp b/js/src/frontend/BinSource-auto.cpp index 3df6f1edcf66..be08ef273987 100644 --- a/js/src/frontend/BinSource-auto.cpp +++ b/js/src/frontend/BinSource-auto.cpp @@ -3860,6 +3860,18 @@ BinASTParser::parseInterfaceCallExpression(const size_t start, const BinKin BINJS_MOZ_TRY_DECL(arguments, parseArguments()); auto op = JSOP_CALL; + + // Try to optimize funcall and funapply at the bytecode level + if (PropertyName* prop = factory_.maybeDottedProperty(callee)) { + if (prop == cx_->names().apply) { + op = JSOP_FUNAPPLY; + if (parseContext_->isFunctionBox()) + parseContext_->functionBox()->usesApply = true; + } else if (prop == cx_->names().call) { + op = JSOP_FUNCALL; + } + } + // Check for direct calls to `eval`. if (factory_.isEvalName(callee, cx_)) { if (!parseContext_->varScope().lookupDeclaredNameForAdd(callee->name()) diff --git a/js/src/frontend/BinSource.yaml b/js/src/frontend/BinSource.yaml index 092c6aa5fdd6..70d6480ae1a5 100644 --- a/js/src/frontend/BinSource.yaml +++ b/js/src/frontend/BinSource.yaml @@ -482,6 +482,18 @@ BreakStatement: CallExpression: build: | auto op = JSOP_CALL; + + // Try to optimize funcall and funapply at the bytecode level + if (PropertyName* prop = factory_.maybeDottedProperty(callee)) { + if (prop == cx_->names().apply) { + op = JSOP_FUNAPPLY; + if (parseContext_->isFunctionBox()) + parseContext_->functionBox()->usesApply = true; + } else if (prop == cx_->names().call) { + op = JSOP_FUNCALL; + } + } + // Check for direct calls to `eval`. if (factory_.isEvalName(callee, cx_)) { if (!parseContext_->varScope().lookupDeclaredNameForAdd(callee->name())