Coder Social home page Coder Social logo

Comments (9)

jasonwilliams avatar jasonwilliams commented on April 19, 2024 1

@vitkarpov sure!

from boa.

jasonwilliams avatar jasonwilliams commented on April 19, 2024 1

@vitkarpov no problem, im still learning myself, mainly start on something then ask questions as needed

from boa.

jasonwilliams avatar jasonwilliams commented on April 19, 2024 1

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.

vitkarpov avatar vitkarpov commented on April 19, 2024

Hey @jasonwilliams, it's nice that you have so clean descriptions of issues 👍 Do you consider to take a PR on this?

from boa.

jasonwilliams avatar jasonwilliams commented on April 19, 2024

@vitkarpov ECMA spec defines 2 methods for calling and constructing an object, maybe this helps:
https://tc39.github.io/ecma262/#table-6

from boa.

jasonwilliams avatar jasonwilliams commented on April 19, 2024

@vitkarpov how you getting on?

from boa.

vitkarpov avatar vitkarpov commented on April 19, 2024

@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.

someguynamedmatt avatar someguynamedmatt commented on April 19, 2024

@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.

jasonwilliams avatar jasonwilliams commented on April 19, 2024

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

@someguynamedmatt

This ticket may need to be broken out to others:
String: jasonwilliams#100

from boa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.