Comments (9)
@vitkarpov sure!
from boa.
@vitkarpov no problem, im still learning myself, mainly start on something then ask questions as needed
from boa.
I've been thinking about this for some time, so sorry for the long write up.
@someguynamedmatt Number()
doesn't work or exist at the moment, there is no Number
object on the global scope at the that's where this ticket comes in: jasonwilliams#34
The number and String pattern in the description was just hypothetical and what we should be aiming for.
Our global function objects (String
, Boolean
, Array
) need refactoring. If you look at the specification these are all function objects, which can create exotic objects or native data types, these function objects have [[Call]] and [[Construct]] internal methods. (this is easier to implement now now Objects have been refactored).
Let's take String as an example. String is exposed to the global scope as a function (make_string) with the methods on its prototype. This is ok for constucting objects but leaves us no room for calling String() normally.
Right now when we construct a new string, we actually just call it like a normal function. This means that in exec.rs Construct and Call are currently doing the same thing (except Construct passes this
as its first argument)
Once function objects have been created exprDef::Construct will need to be more clever to return the [[Construct]] func, and ExprDef::Call will need to be more clever to return the [[Cal]] func
https://github.com/jasonwilliams/boa/blob/master/src/lib/js/string.rs#L556-L558 can go, ive not been a big fan of passing global in just to do that. Instead there should be a ::new()
method which can be pulled into exec.rs
Refactoring
Functions (String(), Boolean(), Array()) should all be function objects to match https://tc39.es/ecma262/#function-object this can re-use https://github.com/jasonwilliams/boa/blob/master/src/lib/js/object.rs#L22-L31
Function Objects
https://tc39.es/ecma262/#function-object
A function object is just a regular object with the [[Call]] and [[Construct]] internal methods set
from boa.
Hey @jasonwilliams, it's nice that you have so clean descriptions of issues 👍 Do you consider to take a PR on this?
from boa.
@vitkarpov ECMA spec defines 2 methods for calling and constructing an object, maybe this helps:
https://tc39.github.io/ecma262/#table-6
from boa.
@vitkarpov how you getting on?
from boa.
@jasonwilliams now so good, actually I have a pretty basic understanding of Rust, so not being able to articulate in a particular language makes this kind of hard 😞
I'd be happy to follow your PRs and ask questions if you don't mind, I'm sure it's going to be better with time.
I'm sorry I didn't tell about it in advance if you're counting on me.
from boa.
@jasonwilliams For clarity: in the description are we suggesting that Number()
works as intended, whereas String()
doesn't? Or are they both not functioning to the spec?
from boa.
A huge amount of the above work is now done. Constructor functions are now function objects which have a [[Construct]] and a [[Call]] method.
The Construct gets used here: https://github.com/jasonwilliams/boa/blob/master/src/lib/exec.rs#L281
Call currently doesn't use the [[Call]] internal slot.
https://github.com/jasonwilliams/boa/blob/master/src/lib/exec.rs#L111
This ticket may need to be broken out to others:
String: jasonwilliams#100
from boa.
Related Issues (20)
- Optimize arrays and array operations
- Web Api support? HOT 2
- oxc as AST Parser? HOT 2
- Add Boa to Test262-Harness
- Cancel/Interrupt active evaluation HOT 3
- perf issue: basic loop is 10 times slower than QJS and 100 times slower than Node
- RegExp exec failed HOT 4
- Move out ICU blobs
- Consider moving some builtins to the `NativeObject` variant of `JsObject` HOT 2
- Add tests for `JsSymbol` HOT 7
- Make a pre-parsing phase to analyze variable scopes
- Calling a function with parameters that was imported via "require/module.exports" causes an error HOT 1
- Function name cannot be reassigned in it's scope.
- How do you properly call an async function under tokio?
- Variables declared without var are not recognized as global in Non-Strict Mode. HOT 4
- Realm `host_defined` and `host_defined_mut` functions aren't accessible HOT 2
- Rust async function stuck indefinitely when called from js HOT 4
- Customizable console
- Ability to call rust function using js "this" and "args" using a utility trait.
- Can't regex match on string containing emoji HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boa.