use super::{Operation, VaryingOperand};
use crate::{Context, JsResult};
#[derive(Debug, Clone, Copy)]
pub(crate) struct HasRestrictedGlobalProperty;
impl HasRestrictedGlobalProperty {
#[inline(always)]
pub(super) fn operation(
(dst, index): (VaryingOperand, VaryingOperand),
context: &mut Context,
) -> JsResult<()> {
let name = &context
.vm
.frame()
.code_block()
.constant_string(index.into());
let value = context.has_restricted_global_property(name)?;
context.vm.set_register(dst.into(), value.into());
Ok(())
}
}
impl Operation for HasRestrictedGlobalProperty {
const NAME: &'static str = "HasRestrictedGlobalProperty";
const INSTRUCTION: &'static str = "INST - HasRestrictedGlobalProperty";
const COST: u8 = 4;
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct CanDeclareGlobalFunction;
impl CanDeclareGlobalFunction {
#[inline(always)]
pub(super) fn operation(
(dst, index): (VaryingOperand, VaryingOperand),
context: &mut Context,
) -> JsResult<()> {
let name = &context
.vm
.frame()
.code_block()
.constant_string(index.into());
let value = context.can_declare_global_function(name)?;
context.vm.set_register(dst.into(), value.into());
Ok(())
}
}
impl Operation for CanDeclareGlobalFunction {
const NAME: &'static str = "CanDeclareGlobalFunction";
const INSTRUCTION: &'static str = "INST - CanDeclareGlobalFunction";
const COST: u8 = 4;
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct CanDeclareGlobalVar;
impl CanDeclareGlobalVar {
#[inline(always)]
pub(super) fn operation(
(dst, index): (VaryingOperand, VaryingOperand),
context: &mut Context,
) -> JsResult<()> {
let name = &context
.vm
.frame()
.code_block()
.constant_string(index.into());
let value = context.can_declare_global_var(name)?;
context.vm.set_register(dst.into(), value.into());
Ok(())
}
}
impl Operation for CanDeclareGlobalVar {
const NAME: &'static str = "CanDeclareGlobalVar";
const INSTRUCTION: &'static str = "INST - CanDeclareGlobalVar";
const COST: u8 = 4;
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct CreateGlobalFunctionBinding;
impl CreateGlobalFunctionBinding {
#[inline(always)]
pub(super) fn operation(
(function, configurable, index): (VaryingOperand, VaryingOperand, VaryingOperand),
context: &mut Context,
) -> JsResult<()> {
let configurable = u32::from(configurable) != 0;
let value = context.vm.get_register(function.into());
let name = context
.vm
.frame()
.code_block()
.constant_string(index.into());
let function = value
.as_object()
.expect("value must be an function")
.clone();
context.create_global_function_binding(name, function, configurable)?;
Ok(())
}
}
impl Operation for CreateGlobalFunctionBinding {
const NAME: &'static str = "CreateGlobalFunctionBinding";
const INSTRUCTION: &'static str = "INST - CreateGlobalFunctionBinding";
const COST: u8 = 2;
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct CreateGlobalVarBinding;
impl CreateGlobalVarBinding {
#[inline(always)]
pub(super) fn operation(
(configurable, index): (VaryingOperand, VaryingOperand),
context: &mut Context,
) -> JsResult<()> {
let configurable = u32::from(configurable) != 0;
let name = context
.vm
.frame()
.code_block()
.constant_string(index.into());
context.create_global_var_binding(name, configurable)?;
Ok(())
}
}
impl Operation for CreateGlobalVarBinding {
const NAME: &'static str = "CreateGlobalVarBinding";
const INSTRUCTION: &'static str = "INST - CreateGlobalVarBinding";
const COST: u8 = 2;
}