v7 icon indicating copy to clipboard operation
v7 copied to clipboard

Trouble passing "true", "false" and "null"

Open fabiosantoscode opened this issue 8 years ago • 3 comments

Some values can't be passed directly to a function.

I was trying to pass true as the first argument to a function, but it got turned into undefined. From what I've seen this happens with false and null as well.

Check the below example and its output (from running ./v7 file.js), written in the comments:

'use strict'

function fn(a, b) { print("a: " + a + ", b: " + b) }

fn(3, 2) // a: 3, b: 2 
fn(true) // a: undefined, b: undefined 
fn(true, true) // a: true, b: undefined 
fn(true, "foo") // a: true, b: foo 

If instead you put the true value in a variable and pass it through that variable, everything works well.

print('-- from a variable')
var trueVar = true

fn(trueVar) // a: true, b: undefined 
fn(trueVar, trueVar) // a: true, b: true 
fn(trueVar, "foo") // a: true, b: foo 

Everything works if true is generated from any expression as well.

I compiled the latest master (as of today) of v7 with the following command:

gcc -O0 -DV7_EXE -DV7_ENABLE_STACK_TRACKING -DV7_ENABLE_FILE v7.c -lm

But even when keeping only -DV7_EXE I can still reproduce this issue.

fabiosantoscode avatar Jul 09 '17 21:07 fabiosantoscode

we are not actively working on v7, please use https://github.com/cesanta/mjs

cpq avatar Jul 10 '17 08:07 cpq

is there any migration guide from v7 to mjs?

ozlb avatar Aug 21 '17 22:08 ozlb

No. The API is quite similar though.

cpq avatar Aug 22 '17 05:08 cpq