-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Implement Typed Arrays #1552
Implement Typed Arrays #1552
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty good draft! Can't wait to see a lot of tests fixed :D
boa/src/value/mod.rs
Outdated
|
||
/// Retrieves value of specific property, when the value of the property is expected to be a function. | ||
/// | ||
/// More information: | ||
/// - [EcmaScript reference][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#sec-getmethod | ||
pub(crate) fn get_method<K>(&self, context: &mut Context, key: K) -> JsResult<JsValue> | ||
where | ||
K: Into<PropertyKey>, | ||
{ | ||
// 1. Assert: IsPropertyKey(P) is true. | ||
// 2. Let func be ? GetV(V, P). | ||
let func = self.get_v(context, key)?; | ||
|
||
// 3. If func is either undefined or null, return undefined. | ||
if func.is_null_or_undefined() { | ||
return Ok(JsValue::undefined()); | ||
} | ||
|
||
// 4. If IsCallable(func) is false, throw a TypeError exception. | ||
if !func.is_callable() { | ||
Err(context | ||
.construct_type_error("value returned for property of object is not a function")) | ||
} else { | ||
// 5. Return func. | ||
Ok(func) | ||
} | ||
} | ||
|
||
/// The `GetV ( V, P )` abstract operation | ||
/// | ||
/// Retrieves the value of a specific property of an ECMAScript language value. If the value is | ||
/// not an object, the property lookup is performed using a wrapper object appropriate for the | ||
/// type of the value. | ||
/// | ||
/// More information: | ||
/// - [EcmaScript reference][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#sec-getmethod | ||
#[inline] | ||
pub(crate) fn get_v<K>(&self, context: &mut Context, key: K) -> JsResult<JsValue> | ||
where | ||
K: Into<PropertyKey>, | ||
{ | ||
// 1. Let O be ? ToObject(V). | ||
let o = self.to_object(context)?; | ||
|
||
// 2. Return ? O.[[Get]](P, V). | ||
o.get(key, context) | ||
} | ||
|
||
/// It determines if the value is a callable function with a `[[Call]]` internal method. | ||
/// | ||
/// More information: | ||
/// - [EcmaScript reference][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#sec-iscallable | ||
#[track_caller] | ||
pub(crate) fn is_callable(&self) -> bool { | ||
if let Self::Object(obj) = self { | ||
obj.is_callable() | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/// Determines if `value` inherits from the instance object inheritance path. | ||
/// | ||
/// More information: | ||
/// - [EcmaScript reference][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#sec-ordinaryhasinstance | ||
pub(crate) fn ordinary_has_instance( | ||
&self, | ||
context: &mut Context, | ||
value: &JsValue, | ||
) -> JsResult<bool> { | ||
if let Self::Object(obj) = self { | ||
obj.ordinary_has_instance(context, value) | ||
} else { | ||
Ok(false) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a JsValue
impl at the bottom of operations.rs
with all the methods of JsValue
that operate on JsObjects
. Maybe this should be put there just to have all the object related operations in the same file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this, I think we should add the is_array()
and so on methods to JsValue
, and also the as_array()
and so on. This would make it easier to only use JsValue
in most places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jedel1043 I think this is solved right?
@Razican Should I open an issue for implementing all the is
and as
methods on JsValue
and looking for some optimizations around the codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is solved right?
Yep, I moved this to operations.rs
Test262 conformance changes:
Fixed tests (1104):
New panics (8):
|
1fea480
to
f7cff7c
Compare
@Razican I implemented some ArrayBuffer methods. I think we will need most of them for Typed Arrays. Lots of new test passes, failures and panics. |
Great! I'm currently lacking free time to work on this, so feel free to contribute more! This could be one of the big features of 0.14 |
Implemented the corresponding internal methods for |
3d7d6a9
to
3e9e75c
Compare
Test262 conformance changes:
Fixed tests (778):
Broken tests (10):
New panics (1430):
|
33d900f
to
6d945f8
Compare
Test262 conformance changes:
Fixed tests (778):
New panics (1430):
|
Fixed the regressing tests :) |
Implemented the initializers, Most panics are fixed now. I'm looking at the rest of those now. |
Started with the implementation of some of the methods for TypedArray. Also added a method to the Test262 conformance changes:
Fixed tests (1998):
New panics (8):
|
The full list of fixed tests is now to big for github comments... Test262 conformance changes:
|
1c5ea9a
to
5af3e23
Compare
I fixed most of the typed array prototype methods. Almost all of the remaining prototype tests are failing (at least in part) due to other features. I think at this stage we should review and merge this. We can open issues for DataView and SharedArrayBuffer based on this. Test262 conformance changes:
|
Unfortunately I had to squash the commits, because rebasing became an absolute nightmare :/ |
Don't worry, we can co-author when merging to master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from changes already mentioned it looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work to everyone!
Hello team! Currently we have at least hundreds or thousands of tests that are failing due to not having Typed Arrays. Even the tester
$262
object is supposed to have them. This PR is supposed to end up implementing Typed Arrays, but I wanted to bring the changes to your attention before moving further (also, because I will have limited free time during some time).This Pull Request fixes/closes #893 (when it's finished).
It changes the following:
GetMethod()
toJsValue
GetV
Feel free to comment or to even push to this branch.