Skip to content
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

Spec Compliant Number.prototype.toString(), better Number object formating and -0 #572

Merged
merged 4 commits into from
Jul 19, 2020

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Jul 16, 2020

This Pull Request is related to #507 .

It changes the following:

  • Made number object printing Number { numberValue }.
  • -0 is now -0 instead of positive 0 this is done by V8 and SpiderMonkey, even though it does against the tostring spec, in REPL we are not bound by the ECMAScript spec so we can do this, it makes it easier to know if the number is a -0 or a positive 0.
  • Made Number.prototype.toString() spec compliant
  • Enabled Number.prototype.toString() tests
new Number(1000); // -> Number { 1000 }

@HalidOdat HalidOdat added enhancement New feature or request execution Issues or PRs related to code execution labels Jul 16, 2020
@HalidOdat HalidOdat added this to the v0.10.0 milestone Jul 16, 2020
@codecov
Copy link

codecov bot commented Jul 16, 2020

Codecov Report

Merging #572 into master will increase coverage by 0.03%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #572      +/-   ##
==========================================
+ Coverage   70.37%   70.40%   +0.03%     
==========================================
  Files         175      175              
  Lines       11145    11162      +17     
==========================================
+ Hits         7843     7859      +16     
- Misses       3302     3303       +1     
Impacted Files Coverage Δ
boa/src/builtins/value/display.rs 75.90% <33.33%> (-5.68%) ⬇️
boa/src/builtins/number/mod.rs 68.32% <100.00%> (+1.03%) ⬆️
boa/src/builtins/number/tests.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c1132d...089d900. Read the comment docs.

@HalidOdat HalidOdat changed the title Number object formating and -0 Spec Comapliant Number.prototype.toString(), better Number object formating and -0 Jul 16, 2020
@HalidOdat HalidOdat changed the title Spec Comapliant Number.prototype.toString(), better Number object formating and -0 Spec Compliant Number.prototype.toString(), better Number object formating and -0 Jul 16, 2020
@HalidOdat HalidOdat added the builtins PRs and Issues related to builtins/intrinsics label Jul 16, 2020
@github-actions
Copy link

Benchmark for b78a596

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 366.4±22.56ns 361.9±21.50ns +1.24%
Arithmetic operations (Full) 177.2±10.69µs 177.5±7.18µs -0.17%
Array access (Execution) 15.3±0.61µs 15.1±0.57µs +1.32%
Array access (Full) 204.0±9.51µs 204.6±10.01µs -0.29%
Array creation (Execution) 3.7±0.16ms 3.7±0.12ms 0.00%
Array creation (Full) 4.0±0.14ms 4.1±0.15ms -2.44%
Array pop (Execution) 1448.6±75.23µs 1451.7±72.90µs -0.21%
Array pop (Full) 1756.3±92.17µs 1770.5±79.89µs -0.80%
Boolean Object Access (Execution) 5.6±0.41µs 5.5±0.26µs +1.82%
Boolean Object Access (Full) 188.5±8.36µs 188.4±9.48µs +0.05%
Create Realm 160.9±11.45µs 160.7±8.01µs +0.12%
Dynamic Object Property Access (Execution) 7.7±0.34µs 7.8±0.39µs -1.28%
Dynamic Object Property Access (Full) 191.8±6.99µs 195.1±10.40µs -1.69%
Expression (Lexer) 2.4±0.11µs 2.5±0.14µs -4.00%
Expression (Parser) 5.2±0.29µs 5.3±0.26µs -1.89%
Fibonacci (Execution) 1082.9±65.99µs 1095.6±59.58µs -1.16%
Fibonacci (Full) 1304.3±65.27µs 1300.7±71.29µs +0.28%
For loop (Execution) 23.6±0.95µs 24.3±1.37µs -2.88%
For loop (Full) 208.8±14.46µs 211.6±12.73µs -1.32%
For loop (Lexer) 5.3±0.25µs 5.2±0.22µs +1.92%
For loop (Parser) 14.3±0.64µs 14.3±0.84µs 0.00%
Goal Symbols (Parser) 8.3±0.38µs 8.3±0.38µs 0.00%
Hello World (Lexer) 855.1±68.56ns 855.4±54.93ns -0.04%
Hello World (Parser) 2.1±0.11µs 2.2±0.23µs -4.55%
Long file (Parser) 6.5±0.28ms 6.4±0.14ms +1.56%
Number Object Access (Execution) 4.3±0.20µs 4.3±0.27µs 0.00%
Number Object Access (Full) 183.9±9.70µs 225.6±11.21µs -18.48%
Object Creation (Execution) 6.7±0.24µs 6.8±0.56µs -1.47%
Object Creation (Full) 210.0±9.65µs 212.8±11.95µs -1.32%
RegExp (Execution) 72.3±3.00µs 72.2±5.03µs +0.14%
RegExp (Full) 313.8±12.81µs 314.1±22.61µs -0.10%
RegExp Literal (Execution) 77.5±4.29µs 76.5±3.23µs +1.31%
RegExp Literal (Full) 277.4±14.45µs 277.3±24.60µs +0.04%
RegExp Literal Creation (Execution) 74.5±4.22µs 73.0±3.79µs +2.05%
RegExp Literal Creation (Full) 309.0±14.66µs 312.2±16.41µs -1.02%
Static Object Property Access (Execution) 7.0±0.33µs 7.0±0.32µs 0.00%
Static Object Property Access (Full) 187.5±6.11µs 189.2±7.93µs -0.90%
String Object Access (Execution) 9.5±0.46µs 9.4±0.50µs +1.06%
String Object Access (Full) 194.0±9.34µs 192.5±12.17µs +0.78%
String comparison (Execution) 7.9±0.35µs 7.6±0.43µs +3.95%
String comparison (Full) 193.9±7.35µs 190.3±6.99µs +1.89%
String concatenation (Execution) 6.5±0.35µs 6.4±0.76µs +1.56%
String concatenation (Full) 192.0±8.52µs 189.3±9.81µs +1.43%
String copy (Execution) 5.2±0.27µs 5.2±0.36µs 0.00%
String copy (Full) 182.1±8.54µs 186.2±9.29µs -2.20%
Symbols (Execution) 4.4±0.38µs 4.4±0.24µs 0.00%
Symbols (Full) 174.0±8.35µs 170.9±6.05µs +1.81%

@github-actions
Copy link

Benchmark for db12adf

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 374.4±9.06ns 367.6±13.17ns +1.85%
Arithmetic operations (Full) 171.2±4.00µs 170.4±5.80µs +0.47%
Array access (Execution) 14.8±0.51µs 14.7±0.71µs +0.68%
Array access (Full) 185.0±6.54µs 185.1±9.06µs -0.05%
Array creation (Execution) 3.8±0.12ms 3.9±0.13ms -2.56%
Array creation (Full) 4.1±0.12ms 4.2±0.15ms -2.38%
Array pop (Execution) 1473.8±93.05µs 1468.1±59.05µs +0.39%
Array pop (Full) 1799.2±54.64µs 1780.8±64.89µs +1.03%
Boolean Object Access (Execution) 5.3±0.13µs 5.2±0.32µs +1.92%
Boolean Object Access (Full) 175.7±7.98µs 174.6±6.18µs +0.63%
Create Realm 153.2±6.40µs 158.9±4.36µs -3.59%
Dynamic Object Property Access (Execution) 7.2±0.38µs 7.2±0.48µs 0.00%
Dynamic Object Property Access (Full) 179.1±6.10µs 176.3±5.97µs +1.59%
Expression (Lexer) 2.3±0.09µs 2.3±0.10µs 0.00%
Expression (Parser) 5.1±0.32µs 5.2±0.26µs -1.92%
Fibonacci (Execution) 1001.7±39.40µs 1026.6±25.25µs -2.43%
Fibonacci (Full) 1196.0±55.54µs 1182.8±33.05µs +1.12%
For loop (Execution) 22.6±0.96µs 23.0±0.96µs -1.74%
For loop (Full) 191.4±11.81µs 195.7±10.53µs -2.20%
For loop (Lexer) 5.2±0.20µs 5.4±0.13µs -3.70%
For loop (Parser) 13.7±0.54µs 14.0±1.27µs -2.14%
Goal Symbols (Parser) 8.8±0.54µs 8.4±0.32µs +4.76%
Hello World (Lexer) 834.9±89.21ns 829.4±30.76ns +0.66%
Hello World (Parser) 2.1±0.18µs 2.2±0.06µs -4.55%
Long file (Parser) 6.3±0.09ms 6.2±0.18ms +1.61%
Number Object Access (Execution) 4.2±0.09µs 4.1±0.13µs +2.44%
Number Object Access (Full) 172.6±6.89µs 216.8±5.31µs -20.39%
Object Creation (Execution) 6.2±0.24µs 6.4±0.22µs -3.13%
Object Creation (Full) 193.8±7.69µs 192.2±9.44µs +0.83%
RegExp (Execution) 67.9±2.27µs 69.0±1.71µs -1.59%
RegExp (Full) 290.3±18.37µs 284.0±11.22µs +2.22%
RegExp Literal (Execution) 70.5±3.25µs 69.3±2.60µs +1.73%
RegExp Literal (Full) 251.7±6.81µs 250.6±9.84µs +0.44%
RegExp Literal Creation (Execution) 68.1±3.03µs 65.7±2.70µs +3.65%
RegExp Literal Creation (Full) 291.2±16.73µs 287.8±7.78µs +1.18%
Static Object Property Access (Execution) 6.6±0.22µs 6.6±0.24µs 0.00%
Static Object Property Access (Full) 175.1±3.73µs 173.6±6.40µs +0.86%
String Object Access (Execution) 9.2±1.10µs 9.1±0.46µs +1.10%
String Object Access (Full) 180.2±6.30µs 175.0±8.28µs +2.97%
String comparison (Execution) 7.0±0.26µs 7.0±0.43µs 0.00%
String comparison (Full) 175.7±8.14µs 179.8±5.86µs -2.28%
String concatenation (Execution) 5.9±0.24µs 5.9±0.29µs 0.00%
String concatenation (Full) 177.9±8.44µs 175.7±3.66µs +1.25%
String copy (Execution) 4.8±0.16µs 4.8±0.62µs 0.00%
String copy (Full) 172.3±5.67µs 173.1±3.90µs -0.46%
Symbols (Execution) 4.0±0.16µs 4.2±0.04µs -4.76%
Symbols (Full) 160.5±5.40µs 168.1±5.92µs -4.52%

@github-actions
Copy link

Benchmark for bfcfa01

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 288.4±18.41ns 291.7±14.32ns -1.13%
Arithmetic operations (Full) 132.8±10.45µs 143.9±18.79µs -7.71%
Array access (Execution) 11.4±0.88µs 11.6±0.81µs -1.72%
Array access (Full) 146.5±7.78µs 144.0±7.43µs +1.74%
Array creation (Execution) 2.9±0.18ms 2.9±0.10ms 0.00%
Array creation (Full) 3.2±0.15ms 3.2±0.14ms 0.00%
Array pop (Execution) 1131.5±56.75µs 1161.5±96.02µs -2.58%
Array pop (Full) 1398.6±71.32µs 1387.7±94.57µs +0.79%
Boolean Object Access (Execution) 4.1±0.23µs 4.2±0.30µs -2.38%
Boolean Object Access (Full) 139.9±10.44µs 135.2±6.50µs +3.48%
Create Realm 122.2±7.91µs 125.5±10.77µs -2.63%
Dynamic Object Property Access (Execution) 5.6±0.26µs 5.7±0.33µs -1.75%
Dynamic Object Property Access (Full) 145.2±13.97µs 137.5±7.93µs +5.60%
Expression (Lexer) 1815.7±113.43ns 2.1±0.26µs -13.54%
Expression (Parser) 4.2±0.36µs 4.4±0.46µs -4.55%
Fibonacci (Execution) 778.5±40.28µs 791.4±63.42µs -1.63%
Fibonacci (Full) 964.0±57.49µs 933.8±59.88µs +3.23%
For loop (Execution) 17.5±1.00µs 18.0±1.05µs -2.78%
For loop (Full) 159.2±13.39µs 151.2±9.55µs +5.29%
For loop (Lexer) 4.1±0.28µs 4.3±0.40µs -4.65%
For loop (Parser) 11.0±1.96µs 10.9±0.69µs +0.92%
Goal Symbols (Parser) 6.4±0.31µs 6.6±0.41µs -3.03%
Hello World (Lexer) 628.1±30.51ns 717.2±80.36ns -12.42%
Hello World (Parser) 1688.6±117.88ns 1735.2±143.46ns -2.69%
Long file (Parser) 4.8±0.15ms 5.0±0.26ms -4.00%
Number Object Access (Execution) 3.3±0.19µs 3.4±0.19µs -2.94%
Number Object Access (Full) 135.9±6.82µs 163.3±9.40µs -16.78%
Object Creation (Execution) 5.0±0.32µs 4.9±0.24µs +2.04%
Object Creation (Full) 152.6±9.05µs 153.2±10.77µs -0.39%
RegExp (Execution) 51.7±4.23µs 51.6±5.15µs +0.19%
RegExp (Full) 227.3±12.41µs 227.8±17.22µs -0.22%
RegExp Literal (Execution) 54.4±3.03µs 54.0±2.75µs +0.74%
RegExp Literal (Full) 206.7±18.30µs 195.2±9.65µs +5.89%
RegExp Literal Creation (Execution) 51.7±3.68µs 51.6±3.03µs +0.19%
RegExp Literal Creation (Full) 229.0±17.02µs 223.9±15.72µs +2.28%
Static Object Property Access (Execution) 5.1±0.26µs 5.2±0.38µs -1.92%
Static Object Property Access (Full) 137.6±8.29µs 137.5±10.95µs +0.07%
String Object Access (Execution) 7.2±0.38µs 7.2±0.41µs 0.00%
String Object Access (Full) 139.8±10.64µs 140.3±8.58µs -0.36%
String comparison (Execution) 5.4±0.25µs 5.5±0.34µs -1.82%
String comparison (Full) 143.7±8.83µs 138.7±7.49µs +3.60%
String concatenation (Execution) 4.6±0.31µs 4.7±0.41µs -2.13%
String concatenation (Full) 147.4±20.20µs 135.6±8.51µs +8.70%
String copy (Execution) 3.7±0.29µs 3.7±0.22µs 0.00%
String copy (Full) 139.5±8.50µs 133.2±13.15µs +4.73%
Symbols (Execution) 3.2±0.17µs 3.2±0.16µs 0.00%
Symbols (Full) 132.3±10.57µs 128.7±6.85µs +2.80%

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice. Check my comments. They are mostly for my understanding :)

boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/value/display.rs Show resolved Hide resolved
@github-actions
Copy link

Benchmark for f2371ee

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 378.5±16.81ns 388.5±9.94ns -2.57%
Arithmetic operations (Full) 180.0±6.29µs 180.1±10.03µs -0.06%
Array access (Execution) 14.8±0.33µs 14.9±0.23µs -0.67%
Array access (Full) 198.8±6.72µs 197.4±5.29µs +0.71%
Array creation (Execution) 3.9±0.09ms 3.8±0.12ms +2.63%
Array creation (Full) 4.2±0.10ms 4.2±0.08ms 0.00%
Array pop (Execution) 1488.0±41.68µs 1476.5±41.71µs +0.78%
Array pop (Full) 1788.5±50.23µs 1832.2±62.62µs -2.39%
Boolean Object Access (Execution) 5.4±0.15µs 5.7±0.86µs -5.26%
Boolean Object Access (Full) 189.7±8.57µs 190.1±4.67µs -0.21%
Create Realm 165.4±5.31µs 162.6±3.07µs +1.72%
Dynamic Object Property Access (Execution) 7.2±0.19µs 7.4±0.14µs -2.70%
Dynamic Object Property Access (Full) 191.9±8.17µs 190.4±5.55µs +0.79%
Expression (Lexer) 2.4±0.11µs 2.4±0.05µs 0.00%
Expression (Parser) 5.4±0.16µs 5.4±0.21µs 0.00%
Fibonacci (Execution) 1023.6±67.00µs 1003.5±22.41µs +2.00%
Fibonacci (Full) 1234.3±34.72µs 1248.7±36.92µs -1.15%
For loop (Execution) 23.5±0.40µs 23.4±0.77µs +0.43%
For loop (Full) 202.9±7.45µs 203.6±5.84µs -0.34%
For loop (Lexer) 5.3±0.29µs 5.3±0.19µs 0.00%
For loop (Parser) 13.9±0.56µs 13.8±0.36µs +0.72%
Goal Symbols (Parser) 8.4±0.45µs 8.4±0.36µs 0.00%
Hello World (Lexer) 826.3±36.18ns 827.9±76.67ns -0.19%
Hello World (Parser) 2.2±0.10µs 2.2±0.06µs 0.00%
Long file (Parser) 6.4±0.14ms 6.3±0.20ms +1.59%
Number Object Access (Execution) 4.3±0.13µs 4.3±0.19µs 0.00%
Number Object Access (Full) 184.4±6.10µs 224.0±6.79µs -17.68%
Object Creation (Execution) 6.3±0.23µs 6.5±0.29µs -3.08%
Object Creation (Full) 206.4±6.59µs 205.4±7.19µs +0.49%
RegExp (Execution) 74.7±8.19µs 68.4±2.49µs +9.21%
RegExp (Full) 308.3±12.65µs 307.5±12.19µs +0.26%
RegExp Literal (Execution) 70.7±2.76µs 71.3±2.76µs -0.84%
RegExp Literal (Full) 269.4±9.06µs 264.8±8.75µs +1.74%
RegExp Literal Creation (Execution) 67.4±3.22µs 69.8±4.87µs -3.44%
RegExp Literal Creation (Full) 303.1±11.31µs 304.8±9.13µs -0.56%
Static Object Property Access (Execution) 6.6±0.31µs 6.7±0.11µs -1.49%
Static Object Property Access (Full) 186.8±5.78µs 188.8±7.48µs -1.06%
String Object Access (Execution) 9.4±0.38µs 10.4±4.41µs -9.62%
String Object Access (Full) 196.4±11.28µs 192.1±5.02µs +2.24%
String comparison (Execution) 7.5±0.53µs 7.1±0.14µs +5.63%
String comparison (Full) 194.3±7.83µs 194.2±6.65µs +0.05%
String concatenation (Execution) 6.2±0.26µs 6.0±0.12µs +3.33%
String concatenation (Full) 198.9±23.80µs 184.5±4.26µs +7.80%
String copy (Execution) 5.0±0.31µs 4.9±0.16µs +2.04%
String copy (Full) 185.4±7.27µs 185.9±10.85µs -0.27%
Symbols (Execution) 4.2±0.16µs 4.2±0.09µs 0.00%
Symbols (Full) 174.0±4.16µs 177.4±4.33µs -1.92%

@HalidOdat HalidOdat merged commit 08a608a into master Jul 19, 2020
@HalidOdat HalidOdat deleted the fix/number-tostring branch July 19, 2020 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants