Skip to content

Commit

Permalink
Update opcode for bug 1793962
Browse files Browse the repository at this point in the history
  • Loading branch information
arai-a authored and nbp committed Mar 13, 2023
1 parent 4ff51f4 commit 212f6bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 56 deletions.
7 changes: 5 additions & 2 deletions crates/emitter/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum ThrowMsgKind {
MissingPrivateOnGet = 5,
MissingPrivateOnSet = 6,
AssignToPrivateMethod = 7,
DecoratorInvalidReturnType = 8,
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -1203,12 +1204,14 @@ impl InstructionWriter {
self.emit_op(Opcode::DebugLeaveLexicalEnv);
}

pub fn recreate_lexical_env(&mut self) {
pub fn recreate_lexical_env(&mut self, lexical_scope_index: GCThingIndex) {
self.emit_op(Opcode::RecreateLexicalEnv);
self.write_g_c_thing_index(lexical_scope_index);
}

pub fn freshen_lexical_env(&mut self) {
pub fn freshen_lexical_env(&mut self, lexical_scope_index: GCThingIndex) {
self.emit_op(Opcode::FreshenLexicalEnv);
self.write_g_c_thing_index(lexical_scope_index);
}

pub fn push_class_body_env(&mut self, lexical_scope_index: GCThingIndex) {
Expand Down
35 changes: 4 additions & 31 deletions crates/stencil/src/copy/FunctionFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class FunctionFlags {
// having a [[Construct]] internal method.
CONSTRUCTOR = 1 << 7,

// A 'Bound Function Exotic Object' created by Function.prototype.bind.
BOUND_FUN = 1 << 8,
// (1 << 8) is unused.

// Function comes from a FunctionExpression, ArrowFunction, or Function()
// call (not a FunctionDeclaration or nonstandard function-statement).
Expand All @@ -75,11 +74,8 @@ class FunctionFlags {
// compile time or SetFunctionName at runtime.
HAS_INFERRED_NAME = 1 << 11,

// Function had no explicit name, but a name was guessed for it anyway. For
// a Bound function, tracks if atom_ already contains the "bound " prefix.
ATOM_EXTRA_FLAG = 1 << 12,
HAS_GUESSED_ATOM = ATOM_EXTRA_FLAG,
HAS_BOUND_FUNCTION_NAME_PREFIX = ATOM_EXTRA_FLAG,
// Function had no explicit name, but a name was guessed for it anyway.
HAS_GUESSED_ATOM = 1 << 12,

// The 'length' or 'name property has been resolved. See fun_resolve.
RESOLVED_NAME = 1 << 13,
Expand Down Expand Up @@ -217,22 +213,8 @@ class FunctionFlags {
}

/* Possible attributes of an interpreted function: */
bool isBoundFunction() const { return hasFlags(BOUND_FUN); }
bool hasInferredName() const { return hasFlags(HAS_INFERRED_NAME); }
bool hasGuessedAtom() const {
static_assert(HAS_GUESSED_ATOM == HAS_BOUND_FUNCTION_NAME_PREFIX,
"HAS_GUESSED_ATOM is unused for bound functions");
bool hasGuessedAtom = hasFlags(HAS_GUESSED_ATOM);
bool boundFun = hasFlags(BOUND_FUN);
return hasGuessedAtom && !boundFun;
}
bool hasBoundFunctionNamePrefix() const {
static_assert(
HAS_BOUND_FUNCTION_NAME_PREFIX == HAS_GUESSED_ATOM,
"HAS_BOUND_FUNCTION_NAME_PREFIX is only used for bound functions");
MOZ_ASSERT(isBoundFunction());
return hasFlags(HAS_BOUND_FUNCTION_NAME_PREFIX);
}
bool hasGuessedAtom() const { return hasFlags(HAS_GUESSED_ATOM); }
bool isLambda() const { return hasFlags(LAMBDA); }

bool isNamedLambda(bool hasName) const {
Expand Down Expand Up @@ -285,11 +267,6 @@ class FunctionFlags {
return setFlags(CONSTRUCTOR);
}

FunctionFlags& setIsBoundFunction() {
MOZ_ASSERT(!isBoundFunction());
return setFlags(BOUND_FUN);
}

FunctionFlags& setIsSelfHostedBuiltin() {
MOZ_ASSERT(isInterpreted());
MOZ_ASSERT(!isSelfHostedBuiltin());
Expand All @@ -310,10 +287,6 @@ class FunctionFlags {

FunctionFlags& setGuessedAtom() { return setFlags(HAS_GUESSED_ATOM); }

FunctionFlags& setPrefixedBoundFunctionName() {
return setFlags(HAS_BOUND_FUNCTION_NAME_PREFIX);
}

FunctionFlags& setSelfHostedLazy() { return setFlags(SELFHOSTLAZY); }
FunctionFlags& clearSelfHostedLazy() { return clearFlags(SELFHOSTLAZY); }
FunctionFlags& setBaseScript() { return setFlags(BASESCRIPT); }
Expand Down
25 changes: 11 additions & 14 deletions crates/stencil/src/copy/Opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <stddef.h>
#include <stdint.h>

#include "js/TypeDecls.h"

// clang-format off
/*
* [SMDOC] Bytecode Definitions
Expand Down Expand Up @@ -1511,7 +1513,8 @@
* except by `JSOp::InitElemArray` and `JSOp::InitElemInc`.
*
* `index` must be an integer, `0 <= index <= INT32_MAX`. If `index` is
* `INT32_MAX`, this throws a RangeError.
* `INT32_MAX`, this throws a RangeError. Unlike `InitElemArray`, it is not
* necessary that the `array` length > `index`.
*
* This instruction is used when an array literal contains a
* *SpreadElement*. In `[a, ...b, c]`, `InitElemArray 0` is used to put
Expand Down Expand Up @@ -1892,16 +1895,10 @@
/*
* Push the call site object for a tagged template call.
*
* `script->getObject(objectIndex)` is the call site object;
* `script->getObject(objectIndex + 1)` is the raw object.
*
* The first time this instruction runs for a given template, it assembles
* the final value, defining the `.raw` property on the call site object
* and freezing both objects.
* `script->getObject(objectIndex)` is the call site object.
*
* Implements: [GetTemplateObject][1], steps 4 and 12-16.
*
* [1]: https://tc39.es/ecma262/#sec-gettemplateobject
* The call site object will already have the `.raw` property defined on it
* and will be frozen.
*
* Category: Functions
* Type: Calls
Expand Down Expand Up @@ -3164,21 +3161,21 @@
*
* Category: Variables and scopes
* Type: Entering and leaving environments
* Operands:
* Operands: uint32_t lexicalScopeIndex
* Stack: =>
*/ \
MACRO(RecreateLexicalEnv, recreate_lexical_env, NULL, 1, 0, 0, JOF_BYTE) \
MACRO(RecreateLexicalEnv, recreate_lexical_env, NULL, 5, 0, 0, JOF_SCOPE) \
/*
* Like `JSOp::RecreateLexicalEnv`, but the values of all the bindings are
* copied from the old block to the new one. This is used for C-style
* `for(let ...; ...; ...)` loops.
*
* Category: Variables and scopes
* Type: Entering and leaving environments
* Operands:
* Operands: uint32_t lexicalScopeIndex
* Stack: =>
*/ \
MACRO(FreshenLexicalEnv, freshen_lexical_env, NULL, 1, 0, 0, JOF_BYTE) \
MACRO(FreshenLexicalEnv, freshen_lexical_env, NULL, 5, 0, 0, JOF_SCOPE) \
/*
* Push a ClassBody environment onto the environment chain.
*
Expand Down
2 changes: 2 additions & 0 deletions crates/stencil/src/copy/ThrowMsgKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ enum class ThrowMsgKind : uint8_t {
MissingPrivateOnGet,
MissingPrivateOnSet,
AssignToPrivateMethod,
// Decorators:
DecoratorInvalidReturnType,
};

JSErrNum ThrowMsgKindToErrNum(ThrowMsgKind kind);
Expand Down
8 changes: 1 addition & 7 deletions crates/stencil/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,13 @@ const SELFHOSTLAZY: u16 = 1 << 6;
#[allow(dead_code)]
const CONSTRUCTOR: u16 = 1 << 7;
#[allow(dead_code)]
const BOUND_FUN: u16 = 1 << 8;
#[allow(dead_code)]
const LAMBDA: u16 = 1 << 9;
#[allow(dead_code)]
const WASM_JIT_ENTRY: u16 = 1 << 10;
#[allow(dead_code)]
const HAS_INFERRED_NAME: u16 = 1 << 11;
#[allow(dead_code)]
const ATOM_EXTRA_FLAG: u16 = 1 << 12;
#[allow(dead_code)]
const HAS_GUESSED_ATOM: u16 = ATOM_EXTRA_FLAG;
#[allow(dead_code)]
const HAS_BOUND_FUNCTION_NAME_PREFIX: u16 = ATOM_EXTRA_FLAG;
const HAS_GUESSED_ATOM: u16 = 1 << 12;
#[allow(dead_code)]
const RESOLVED_NAME: u16 = 1 << 13;
#[allow(dead_code)]
Expand Down
4 changes: 2 additions & 2 deletions crates/stencil/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ macro_rules! using_opcode_database {
(PushLexicalEnv, push_lexical_env, NULL, 5, 0, 0, JOF_SCOPE),
(PopLexicalEnv, pop_lexical_env, NULL, 1, 0, 0, JOF_BYTE),
(DebugLeaveLexicalEnv, debug_leave_lexical_env, NULL, 1, 0, 0, JOF_BYTE),
(RecreateLexicalEnv, recreate_lexical_env, NULL, 1, 0, 0, JOF_BYTE),
(FreshenLexicalEnv, freshen_lexical_env, NULL, 1, 0, 0, JOF_BYTE),
(RecreateLexicalEnv, recreate_lexical_env, NULL, 5, 0, 0, JOF_SCOPE),
(FreshenLexicalEnv, freshen_lexical_env, NULL, 5, 0, 0, JOF_SCOPE),
(PushClassBodyEnv, push_class_body_env, NULL, 5, 0, 0, JOF_SCOPE),
(PushVarEnv, push_var_env, NULL, 5, 0, 0, JOF_SCOPE),
(EnterWith, enter_with, NULL, 5, 1, 0, JOF_SCOPE),
Expand Down

0 comments on commit 212f6bd

Please sign in to comment.