Re: [v8-users] Is V8::JSON::Parse really needed against JSON inputs?

2017-03-16 Thread Jakob Kummerow
Of course it's possible to make C++ objects accessible to JS, that's what
V8's API is for. You'll have to provide accessors for fields you want to
expose. See
https://github.com/v8/v8/wiki/Embedder's-Guide#accessing-dynamic-variables.

On Thu, Mar 16, 2017 at 6:04 PM, Abhishek Singh  wrote:

> Hi,
>
> (responses inline)
>
> On 16-Mar-2017, at 21:53, Jakob Kummerow  wrote:
>
> What do you mean by "native JS JSON"?
>
>
> Apologies, it isn’t technically correct term. I meant javascript object
> carved out of string representation.
>
> JSON ("JavaScript Object Notation") is a standardized format for string
> representations of objects. "JSON.stringify" creates this string
> representation for a given object, "JSON.parse" creates a new object from
> this string representation. If you want to transfer a string, and then
> create an object from it, then JSON.Parse (which is exposed as
> V8::JSON::Parse in the V8 API) is the way to go.
>
>
> (Depending on your use case, instead of transferring a JSON string,
> passing around an ArrayBuffer with externalized data might be a better fit.
> Then there would be no conversions to string and back.)
>
>
> For current use case, I need to operate on few top level fields of JS
> object(made out of stringified representation on already JSON marshalled
> data) - so I think ArrayBuffer might not work out. Sample ex:
>
> function OnUpdate(doc, meta) {
>
> if (doc.type == “credit_score”) {
> var res = CalculateCreditScore(doc)
> }
> }
>
> 2 args passed to OnUpdate->Call() are already JSON marshalled(but present
> as string, so was hoping if I could avoid marshalling it twice). I suppose,
> I would have to stick JSON.parse to handle above kind of use case.
>
> Is there a way to expose a custom encoded data(flatbuffer encoded
> probably, it’s cpu footprint looks good) to JS world and access fields from
> it - i.e. args passed to OnUpdate->Call() could be stringified flatbuffer
> encoded data and then somehow we could access fields in flatbuffer schema
> directly from JS?
>
>
>
>
> On Thu, Mar 16, 2017 at 3:39 PM, Abhishek Singh <
> singhabhishek@gmail.com> wrote:
>
>> Hi,
>>
>> I'm trying to send JSON data to user supplied JS code, which is executed
>> by V8. What I've realised is even if user data is JSON marshalled, I've to
>> explicitly do V8::JSON::Parse on it, so that value received in JS world is
>> native JS JSON. Is that really necessary? Performance penalty because of
>> it, is quite high(screenshot of profile attached).
>>
>>
>>
>> 
>>
>>
>> --
>> --
>> v8-users mailing list
>> v8-users@googlegroups.com
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to v8-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] Is V8::JSON::Parse really needed against JSON inputs?

2017-03-16 Thread Abhishek Singh
Hi,

(responses inline)

> On 16-Mar-2017, at 21:53, Jakob Kummerow  wrote:
> 
> What do you mean by "native JS JSON"?
> 

Apologies, it isn’t technically correct term. I meant javascript object carved 
out of string representation.

> JSON ("JavaScript Object Notation") is a standardized format for string 
> representations of objects. "JSON.stringify" creates this string 
> representation for a given object, "JSON.parse" creates a new object from 
> this string representation. If you want to transfer a string, and then create 
> an object from it, then JSON.Parse (which is exposed as V8::JSON::Parse in 
> the V8 API) is the way to go.
> 
> (Depending on your use case, instead of transferring a JSON string, passing 
> around an ArrayBuffer with externalized data might be a better fit. Then 
> there would be no conversions to string and back.)

For current use case, I need to operate on few top level fields of JS 
object(made out of stringified representation on already JSON marshalled data) 
- so I think ArrayBuffer might not work out. Sample ex:

function OnUpdate(doc, meta) {

if (doc.type == “credit_score”) {
var res = CalculateCreditScore(doc)
}
}

2 args passed to OnUpdate->Call() are already JSON marshalled(but present as 
string, so was hoping if I could avoid marshalling it twice). I suppose, I 
would have to stick JSON.parse to handle above kind of use case.

Is there a way to expose a custom encoded data(flatbuffer encoded probably, 
it’s cpu footprint looks good) to JS world and access fields from it - i.e. 
args passed to OnUpdate->Call() could be stringified flatbuffer encoded data 
and then somehow we could access fields in flatbuffer schema directly from JS?


> 
> 
> On Thu, Mar 16, 2017 at 3:39 PM, Abhishek Singh  > wrote:
> Hi,
> 
> I'm trying to send JSON data to user supplied JS code, which is executed by 
> V8. What I've realised is even if user data is JSON marshalled, I've to 
> explicitly do V8::JSON::Parse on it, so that value received in JS world is 
> native JS JSON. Is that really necessary? Performance penalty because of it, 
> is quite high(screenshot of profile attached).
> 
> 
>  
> 
> 
> 
> -- 
> -- 
> v8-users mailing list
> v8-users@googlegroups.com 
> http://groups.google.com/group/v8-users 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to v8-users+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .
> 
> 
> -- 
> -- 
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to v8-users+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Is V8::JSON::Parse really needed against JSON inputs?

2017-03-16 Thread Abhishek Singh
Hi,

I'm trying to send JSON data to user supplied JS code, which is executed by 
V8. What I've realised is even if user data is JSON marshalled, I've to 
explicitly do V8::JSON::Parse on it, so that value received in JS world is 
native JS JSON. Is that really necessary? Performance penalty because of 
it, is quite high(screenshot of profile attached).




-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] ASCII null character in script

2017-03-16 Thread Daniel Ehrenberg
V8 works towards implementing the ECMAScript spec, which you can find at
https://tc39.github.io/ecma262/ . It doesn't provide any compatibility
modes for other versions of JavaScript shipped by particular browsers, or
historical versions of JavaScript. In standard JS, the null byte is not a
whitespace character, so it makes sense for V8 to throw a SyntaxError.

Dan

On Thu, Mar 16, 2017 at 11:05 AM, Danny Dorfman 
wrote:

> Hello there,
>
> I have been given a script sample that contains a null character (ASCII
> 0x00).
>
> 
> 
> 
> alert("I am an alert box!");
> ^@
> 
> 
> 
>
> Obviously, this fails to compile and run, since this is not valid syntax
> (I get "SyntaxError: Invalid or unexpected token").
> However, in IE this code just gives out a warning, and runs normally.
>
> Is it possible to simulate the IE behavior under V8 as well?
>
> Thanks in advance,
> D.
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] ASCII null character in script

2017-03-16 Thread Danny Dorfman
Hello there,

I have been given a script sample that contains a null character (ASCII 
0x00).




alert("I am an alert box!");
^@
   



Obviously, this fails to compile and run, since this is not valid syntax (I 
get "SyntaxError: Invalid or unexpected token").
However, in IE this code just gives out a warning, and runs normally.

Is it possible to simulate the IE behavior under V8 as well?

Thanks in advance,
D.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.