-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Make forward reference weak gc - Add shape property table cache - Implement unique shape - Implement unique shape property deleting delete - Move property desciptor flags to shape - Remove unneeded Option in property_table - Implement shared property table - Remove unneeded return of insert and remove - Implement prototype transitions - Implement varying width property storage - Convert shape to unique if shape has exceeded transition max - Add documentation - Add `shape.md` documentation - Use FxHashMap for lookup and vec for keys - Direct initialization of arrays and objects with shape - Make functions share the same shape - Apply shared shapes to builtins - Add forward reference check for attribute change - Direct initialization of arrays - Remove overwritten length property on TypedArray - Refactor templates into separate struct - Apply shapes to callable builtins - Initialize builtin constructors directly
- Loading branch information
Showing
78 changed files
with
3,245 additions
and
1,079 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use boa_engine::{ | ||
js_string, object::ObjectInitializer, Context, JsArgs, JsNativeError, JsObject, JsResult, | ||
JsValue, NativeFunction, | ||
}; | ||
|
||
fn get_object(args: &[JsValue], position: usize) -> JsResult<&JsObject> { | ||
let value = args.get_or_undefined(position); | ||
|
||
let Some(object) = value.as_object() else { | ||
return Err(JsNativeError::typ() | ||
.with_message(format!("expected object in argument position {position}, got {}", value.type_of())) | ||
.into()); | ||
}; | ||
|
||
Ok(object) | ||
} | ||
|
||
/// Returns object's shape pointer in memory. | ||
fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> { | ||
let object = get_object(args, 0)?; | ||
let object = object.borrow(); | ||
let shape = object.shape(); | ||
Ok(format!("0x{:X}", shape.to_addr_usize()).into()) | ||
} | ||
|
||
/// Returns object's shape type. | ||
fn r#type(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> { | ||
let object = get_object(args, 0)?; | ||
let object = object.borrow(); | ||
let shape = object.shape(); | ||
|
||
Ok(if shape.is_shared() { | ||
js_string!("shared") | ||
} else { | ||
js_string!("unique") | ||
} | ||
.into()) | ||
} | ||
|
||
/// Returns object's shape type. | ||
fn same(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> { | ||
let lhs = get_object(args, 0)?; | ||
let rhs = get_object(args, 1)?; | ||
|
||
let lhs_shape_ptr = { | ||
let object = lhs.borrow(); | ||
let shape = object.shape(); | ||
shape.to_addr_usize() | ||
}; | ||
|
||
let rhs_shape_ptr = { | ||
let object = rhs.borrow(); | ||
let shape = object.shape(); | ||
shape.to_addr_usize() | ||
}; | ||
|
||
Ok(JsValue::new(lhs_shape_ptr == rhs_shape_ptr)) | ||
} | ||
|
||
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject { | ||
ObjectInitializer::new(context) | ||
.function(NativeFunction::from_fn_ptr(id), "id", 1) | ||
.function(NativeFunction::from_fn_ptr(r#type), "type", 1) | ||
.function(NativeFunction::from_fn_ptr(same), "same", 2) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.