Git Product home page Git Product logo

moddable's People

Contributors

andycarle avatar bmeck avatar fivdi avatar lprader avatar mkellner avatar phoddie avatar pmcneil avatar rwaldron avatar sburel avatar schernykh avatar sebastien-burel avatar tevador avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

schernykh

moddable's Issues

Rounding

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.

Difference between XS and V8 with invalid assignments

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.

Segmentation fault in xsAllocator.c:74

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?

Difference between XS and V8 with invalid RegExp

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

JSON.stringify cannot handle RegExp

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

Eval preventing const declaration in the caller scope

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;"

Integer overflow

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

JSON.stringify incorrectly considers object cyclic

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:

  1. Save the above sample code to file "circular.js".
  2. Run ./xst -s circular.js
  3. Observe output:
Number of keys: 0
TypeError: JSON.stringify: cyclic value

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.