Comments (14)
@jasonwilliams I believe this list is missing replaceAll.
from boa.
I have started to write some implementations for concat() and repeat() but have encountered an issue: currently none of the String prototype methods work, even existing charAt and charCodeAt:
Using:
let a = "Hello world".chatAt(2);
console.log(a);
Results in the buffer holding only: "Error: undefined"
Is this a known issue or needs to be resolved before prototype methods can be added?
from boa.
Hey @CallumQuick hmm that’s interesting
could you try doing new String(“Hello world”) instead of “Hello world”.charAt() ? I think that may work.
When you make a string literal and immediately use a string prototype method on it, you’re using a string object prototype method on a literal string. Engines will box that value into a String object, Boa doesn’t do this yet, so that will most likely be the reason it doesn’t work.
There is still some work to do here around boxing and unboxing and the best approach.
https://github.com/getify/You-Dont-Know-JS/blob/master/types%20%26%20grammar/ch3.md#boxing-wrappers
from boa.
Thanks @jasonwilliams, generating the string via new String(..)
is working with charAt(), charCodeAt(). Will now test with my new implementations.
from boa.
On the topic of the boxing of the primitive string, the only current issue with concat(), repeat(), slice() and the other methods that should return strings is that through to_value()
they come out as "string literals" again. This means you can't do the following:
let a = new String("Hello world");
a.concat("! ").repeat(2);
Is there an easy way to cause concat, repeat etc to return not just string "values" but string objects? Would this be solved by auto-boxing string literals (#29)?
from boa.
Now you're asking the interesting questions!
We can't do this because the return type of those methods are string
types not objects.
Those strings would need to be re-boxed again (yep this is why boxing/un-boxing is a big performance hit and engines often try to find ways around it).
It would be against the spec to return a String instance instead of a string literal.
https://tc39.es/ecma262/#sec-string.prototype.concat
Would this be solved by auto-boxing string literals (#29)?
Basically yes. I think some research would need to be done in this area as i believe there are ways to optimise this operation rather than simply boxing and unboxing again.
In theory we can detect a method being called on a string, so at that point we could convert into a String instance call the method then throw away the instance (wasteful).
There is 1 place where i break this rule and just give back the value, that is when calling length on a string literal. https://github.com/jasonwilliams/boa/blob/master/src/lib/js/value.rs#L202-L208
from boa.
@jasonwilliams Thanks for clarifying the spec's position (I had overlooked the subtlety of the concat/repeat/slice methods returning values only).
As a heads up, next I will probably take a look at the set of these methods which take a "searchString" argument (so not patterns yet): startsWith(), endsWith(), includes(), indexOf() and lastIndexOf().
from boa.
Hey, the links in this issue are out of date due to some code reorg!
Current location of String is here
from boa.
Hey, the links in this issue are out of date due to some code reorg!
Current location of String is here
Good catch! I updated the links, but note that some of this is probably blocked until #419 lands :)
from boa.
@joshwd36 has implemented String.prototype[@@Symbol.iterator]
in #704 , keeping track who has implemented what :)
from boa.
Added split()
, being worked on in #1026
from boa.
@neeldug there's still a few methods in the check list, should this issue be closed?
from boa.
Shouldn’t be closed, only checked off.
from boa.
Closing in favour of #1562.
from boa.
Related Issues (20)
- Ability to call rust function using js "this" and "args" using a utility trait.
- Can't regex match on string containing emoji HOT 2
- Panic on invalid input to boa::parse HOT 1
- Tracking issue for migrating `boa_temporal` to a new repo HOT 5
- Integrating Boa into Biome HOT 7
- RUSTSEC-2024-0014: `generational-arena` is unmaintained HOT 1
- Split `boa_tester` into crates HOT 2
- Possible Incompleteness HOT 1
- Tracking issue for the `Intl` builtin object HOT 1
- Intl: Implement `supportedLocalesOf` for services
- Intl: Extract implementation into a separate crate
- Intl: Remove hacks to get the supported locales of a service HOT 1
- Add backtraces to errors HOT 2
- Explore other storage methods for our test results HOT 12
- custom `JsValue` for better embed HOT 2
- Restrict Direct Construction of `JsValue` to Ensure Invariants HOT 4
- Function.prototyp.toString only returns a fixed `[native code]` string
- Relative imports in SimpleModuleLoader fail to resolve HOT 4
- `Context::get_active_script_or_module` should return a script or module when using import in a generator HOT 1
- Simplifying Function Binding HOT 4
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.