Skip to content

Commit

Permalink
Disallow changing type of already created objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Oct 23, 2023
1 parent cec9892 commit 02adff4
Show file tree
Hide file tree
Showing 19 changed files with 492 additions and 611 deletions.
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
15 changes: 4 additions & 11 deletions boa_engine/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use crate::{
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError,
js_string,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData, ObjectKind},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::{common::StaticJsStrings, utf16},
Context, JsArgs, JsResult, JsString, JsValue, NativeFunction,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand Down Expand Up @@ -115,16 +115,14 @@ pub(crate) struct ThrowTypeError;

impl IntrinsicObject for ThrowTypeError {
fn init(realm: &Realm) {
fn throw_type_error(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let obj = BuiltInBuilder::callable_with_intrinsic::<Self>(realm, |_, _, _| {
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())
.static_property(utf16!("name"), js_string!(), Attribute::empty())
Expand All @@ -133,11 +131,6 @@ 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),
constructor: None,
realm: realm.clone(),
}
}

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

0 comments on commit 02adff4

Please sign in to comment.