Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow changing type of already created objects #3410

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions boa_ast/src/expression/regexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ pub struct RegExpLiteral {
}

impl RegExpLiteral {
/// Create a new [`RegExp`].
/// Create a new [`RegExpLiteral`].
#[inline]
#[must_use]
pub const fn new(pattern: Sym, flags: Sym) -> Self {
Self { pattern, flags }
}

/// Get the pattern part of the [`RegExp`].
/// Get the pattern part of the [`RegExpLiteral`].
#[inline]
#[must_use]
pub const fn pattern(&self) -> Sym {
self.pattern
}

/// Get the flags part of the [`RegExp`].
/// Get the flags part of the [`RegExpLiteral`].
#[inline]
#[must_use]
pub const fn flags(&self) -> Sym {
Expand Down
6 changes: 3 additions & 3 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn evaluate_files(
Err(v) => eprintln!("Uncaught {v}"),
}
} else if args.module {
let result = (|| {
let result: JsResult<PromiseState> = (|| {
let module = Module::parse(Source::from_bytes(&buffer), None, context)?;

loader.insert(
Expand All @@ -334,10 +334,10 @@ fn evaluate_files(
module.clone(),
);

let promise = module.load_link_evaluate(context)?;
let promise = module.load_link_evaluate(context);

context.run_jobs();
promise.state()
Ok(promise.state())
})();

match result {
Expand Down
31 changes: 16 additions & 15 deletions boa_engine/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::{
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError,
js_string,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData, ObjectKind},
native_function::NativeFunctionObject,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::{common::StaticJsStrings, utf16},
Expand Down Expand Up @@ -115,15 +116,6 @@ pub(crate) struct ThrowTypeError;

impl IntrinsicObject for ThrowTypeError {
fn init(realm: &Realm) {
fn throw_type_error(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message(
"'caller', 'callee', and 'arguments' properties may not be accessed on strict mode \
functions or the arguments objects for calls to them",
)
.into())
}

let obj = BuiltInBuilder::with_intrinsic::<Self>(realm)
.prototype(realm.intrinsics().constructors().function().prototype())
.static_property(utf16!("length"), 0, Attribute::empty())
Expand All @@ -132,12 +124,21 @@ impl IntrinsicObject for ThrowTypeError {

let mut obj = obj.borrow_mut();

obj.extensible = false;
*obj.kind_mut() = ObjectKind::NativeFunction {
function: NativeFunction::from_fn_ptr(throw_type_error),
*obj.as_native_function_mut()
.expect("`%ThrowTypeError%` must be a function") = NativeFunctionObject {
f: NativeFunction::from_fn_ptr(|_, _, _| {
Err(JsNativeError::typ()
.with_message(
"'caller', 'callee', and 'arguments' properties may not be accessed on strict mode \
functions or the arguments objects for calls to them",
)
.into())
}),
constructor: None,
realm: realm.clone(),
}
realm: Some(realm.clone()),
};

obj.extensible = false;
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
Loading
Loading