tevador / moddable Goto Github PK
View Code? Open in Web Editor NEWThis project forked from moddable-opensource/moddable
JavaScript engine to be used for cryptocurrency proof-of-work.
This project forked from moddable-opensource/moddable
JavaScript engine to be used for cryptocurrency proof-of-work.
Nonstandard rounding is used when converting a number to decimal string.
XS:
./xst -e "print(17876395023154640000/-13528.07885)"
-1321428949473830.3
V8:
node -e "console.log(17876395023154640000/-13528.07885)"
-1321428949473830.2
The correct value is -1321428949473830.25
and should be rounded to -1321428949473830.2
using the standard 'roundTiesToEven' mode.
XS and V8 differ in the way how they treat invalid assignments.
Examples:
xst -e "function f() { print('Function f called'); } f()=2;"
ReferenceError: no reference
node -e "function f() { console.log('Function f called'); } f()=2;"
Function f called
ReferenceError: Invalid left-hand side in assignment
Here we try to assign a value to a function call. This throws a ReferenceError because the left hand side is not a variable. However, the V8 throws this error after the function is called, while the XS never calls the function.
Same behavior is observed when calling a tagged template.
This may be a violation of the ES6 specification by the V8.
Debug and release builds on raspberry pi (ARMv7 Processor rev 4 (v7l), BCM2835) give:
gdb --args ./xst asdf
...
Program received signal SIGSEGV, Segmentation fault.
0x0001f778 in AllocateNewChunks (index=2)
at /home/pi/moddable/xs/sources/xsAllocator.c:74
74 ((struct SChunk*)(ptr + i))->next = (struct SChunk*)(ptr + i + chunk_size);
(gdb) up
#1 0x0001f854 in my_malloc (size=4)
at /home/pi/moddable/xs/sources/xsAllocator.c:94
94 chunk = AllocateNewChunks(index);
(gdb)
#2 0x0001f9f0 in my_calloc (num=4, size=4)
at /home/pi/moddable/xs/sources/xsAllocator.c:143
143 void* ptr = my_malloc(size);
(gdb)
#3 0x0003b828 in fxInitializeSharedCluster ()
at /home/pi/moddable/xs/sources/xsAtomics.c:515
515 gxSharedCluster = c_calloc(sizeof(txSharedCluster), 1);
(gdb)
#4 0x00116b38 in main (argc=2, argv=0x7efff004)
at /home/pi/moddable/xs/tools/xst.c:218
218 fxInitializeSharedCluster();
Is this a real bug or am I just using it wrong?
xst -e "let a = 0; try{a++ - /+e++/;}catch(e){print(e);} print(a);"
SyntaxError: invalid regular expression: invalid regular expression:
0
node -e "let a = 0; try{a++ - /+e++/;}catch(e){console.log(e);} console.log(a);"
SyntaxError: Invalid regular expression: /+e++/: Nothing to repeat
1
Here we try to subtract invalid regular expression from a++
. The XS fails with an early SyntaxError without executing the code withing the try
block. The V8 however evaluates the a++
expression before throwing the error.
This is a bug in the V8: https://bugs.chromium.org/p/v8/issues/detail?id=896
xst -e "print(JSON.stringify(/aaa/))"
undefined
node -e "console.log(JSON.stringify(/aaa/))"
{}
The output from the V8 is the correct one (RegExp is an object with no enumerable properties).
Specification:
Strict mode eval code cannot instantiate variables or functions in the variable environment of the caller to eval. Instead, a new variable environment is created and that environment is used for declaration binding instantiation for the eval code (18.2.1).
xst -e "'use strict'; eval('e=1'); const e = 0;"
ReferenceError: ?: set e: already initialized
Works with a non-constant variable:
xst -e "'use strict'; eval('e=1'); let e = 0;"
xst -e "let c = eval('c=1'); print(c);"
1
node -e "let c = eval('c=1'); console.log(c);"
ReferenceError: c is not defined
Seems like the Temporal dead zone is not supported inside eval.
Numbers in javascript are floats, but this code produces what appears to be an integer overflow:
./xst -e "let q = 2000000000; print(q); q -= (-2000000000); print(q);"
Expected result:
2000000000
4000000000
Actual result (Windows build):
2000000000
-294967296
Actual result (Linux build):
2000000000
1705032704
Sample code:
let x = {};
x.a = x;
try {
JSON.stringify(x);
} catch(e) {}
delete x.a;
print('Number of keys: ' + Object.keys(x).length);
JSON.stringify(x); //throws here
It seems like the engine 'remembers' that an object had a circular reference and subsequent calls to JSON.stringify fail even if the object is not circular anymore.
Steps to reproduce:
./xst -s circular.js
Number of keys: 0
TypeError: JSON.stringify: cyclic value
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.