[v8-users] Re: MSVC will be unsupported after V8 version 13.0

2024-06-17 Thread J Decker


On Monday, June 17, 2024 at 12:58:19 AM UTC-7 hpa...@chromium.org wrote:

Hi all,

V8 will follow Chromium's lead 
 and 
will discontinue support for MSVC. To give projects time to adjust, we will 
stop support after V8 version 13.0 in September 2024. After that, we will 
remove the infrastructure bots and MSVC compatibility hacks in the code 
base.

 
Node uses MSVC to build on windows, which in turn uses V8; and I have a 
native plugin, which uses a node load hook, a little libuv, and a lot of 
v8; and I would miss VS Debugger... what do you use to build on windows?

I've found that the runtime for node/v8 and the native plugin need to 
match; I tried building using MinGW, but found incompatibilities between 
MinGW C++ and whatever VS C++ generated... 

Please don't? I understand there are costs, and I think I'm a less than 
quiet minority.

J
 


Cheers,
Hannes

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/5c0a58c1-7ae6-40d6-814d-bea08d48eb79n%40googlegroups.com.


Re: [v8-users] Return a Weak Persistent to JS

2021-01-19 Thread J Decker
On Tue, Jan 19, 2021 at 4:44 AM Vinayaka Kamath <
vinayaka.kam...@couchbase.com> wrote:

> Is there any better way to do it? Basically I am exposing an Object
> Template to JS through weak persistent handle and it holds internal
> resources with it. When the object is no longer accessible in the current
> executing scope of the JS code, I want to free up all the resources held by
> the instance of Object Template(maybe through some callback).  At first
> glance it seems like this is what weak handles are meant for.
>
>
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L886-L890
(using setweak)

https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L836  (the
release callback)

don't need persistent... which are things that shouldn't be garbage
collected...

Node's ObjectWrap class is a generic thing used to wrap C++ classes in JS
objects which get garbage collected and have their destructor called...
http://thlorenz.com/node-dox//build/node-v8.x/html/d4/d14/node__object__wrap_8h_source.html


> On Tuesday, January 19, 2021 at 6:05:16 PM UTC+5:30 Ben Noordhuis wrote:
>
>> On Tue, Jan 19, 2021 at 12:26 PM Vinayaka Kamath
>>  wrote:
>> >
>> > It seems like the v8 is crashing when I follow this. To add more to
>> what I am trying to do, when the "value" goes out of scope I want it to get
>> garbage collected and in the callback, I am freeing up resources held by
>> the value. I am basically forcing GC using isolate->LowMemoryNotification()
>> only when I am creating a new item that holds the same type of resource as
>> of that of "value". I've ensured that I'm calling LowMemoryNotification()
>> in the same thread as that of persistent->setWeak(). However one of the
>> threads running the process is crashing.
>>
>> Not a direct answer to your question but it sounds like you're
>> approaching this wrong. The garbage collector is not a good mechanism
>> for deterministic resource management.
>>
>> I also get the impression that you have the wrong idea what "weak"
>> means here: it's not weak in the sense that it's immediately eligible
>> for collection, only when there are no strong references (and only
>> when the garbage collector feels like it - V8's GC is very lazy.)
>>
>> If your JS code is the functional equivalent of `globalThis.value =
>> create()`, then you can call LowMemoryNotification() all you want but
>> it's never going to get collected.
>>
> --
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/9dcf1983-b2c2-4882-8bcc-8140fdc11e90n%40googlegroups.com
> 
> .
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqWPikE_sTvsL%3DWnXO3R_Pv%3DLbGy91%3Dt-dV_V%3DmQm7i8tA%40mail.gmail.com.


Re: [v8-users] Return a Weak Persistent to JS

2021-01-18 Thread J Decker
On Mon, Jan 18, 2021 at 5:28 AM Vinayaka Kamath <
vinayaka.kam...@couchbase.com> wrote:

> Hello All,
>
> I am trying to return a weak persistent handle to JS through a function
> template. However the v8 is crashing on triggering the codepath. What is
> the correct way to do it?
> My intention is to trigger GC on the persistent handle when it goes out of
> scope.
>
> _
> *My Function Template:*
>
> void QueryFunction(const v8::FunctionCallbackInfo ) {
>   // This function is made available as Query() in the JS code
>.
>.
> auto wrapper = new Query::WrapStop(isolate, iterator,
> it_info.iterable);
> args.GetReturnValue().Set(wrapper->value);   *// How to return this??
> Set requires a pointer to Persistent*
>


   args.GetReturnValue().Set(wrapper->value.Get(Isolate));   *// return a
reference to the persistent object.*



> // The intention is to force GC on wrapper->value when it goes out of
> scope in JS
> }
> 
> *Definition of WrapStop*
>
> struct WrapStop {
>explicit WrapStop(v8::Isolate *, Query::Iterator *,
> v8::Local);
>virtual ~WrapStop();
>v8::Persistent value;// Force GC on this handle when
> it goes out of scope
>Query::Iterator *iterator;
> static void Callback(const v8::WeakCallbackInfo &); //
> Callback triggered on GC
> };
> 
> *Constructor for WrapStop*
>
> Query::WrapStop::WrapStop(v8::Isolate *isolate, Query::Iterator *iter,
> v8::Local val) : value(isolate, val), iterator(iter) {
>   value.SetWeak(this, Query::WrapStop::Callback,
> v8::WeakCallbackType::kParameter);
>   // Set value as weak to force GC
> }
>
>
>
> --
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/490983ae-fd94-4b3e-aa4b-0b4ff8e0c23dn%40googlegroups.com
> 
> .
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqUBTkrXjRettWUSk7mtfKzqxhufdk9wjHdf%3DQi3%3D%3DkgDw%40mail.gmail.com.


[v8-users] Re: Trying to beat V8's regex engine with just JS

2020-12-17 Thread J Decker

https://swtch.com/~rsc/regexp/regexp1.html ?

On Tuesday, December 15, 2020 at 5:23:35 AM UTC-8 Peter Martischka wrote:

> Hello v8-users!
>
> In the past I often had a regex as bottleneck in my projects, rewriting 
> them manually to JS often helped. So I recently thought, could I write 
> something that generates the fitting JS for a given regex? Out of that came 
> RECO - https://github.com/Pita/reco . Unfortunately the generated code 
> can't get quite as fast yet. It still takes about 2-3 times in benchmarks 
> compared to the built in regex engine. But it can match all sorts of 
> complicated regex patterns. In manual attempts to rewrite a regex I could 
> often beat the built-in time. 
>
> I would appreciate very much help in making the generated code faster and 
> make it beat the built-in matcher every time. Any help is appreciated, 
> thank you :)
>
> Peter
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/3a5c2356-35af-401a-9ae9-f37a48682309n%40googlegroups.com.


[v8-users] JS Optimizations - how much does the code generator assume?

2020-03-24 Thread J Decker
Say I have this snippet of code 

{
var no_overlap = true;//( pd.algorithm == match_types.TwoGroupsNoOver ) 
//|| ( pd.algorithm == match_types.TwoGroupsPrimeNoOver );
//var prime = ( pd.algorithm == match_types.TwoGroupsPrime ) 
// || ( pd.algorithm == match_types.TwoGroupsPrimeNoOver );
var g;
var masks = []
var index = [];
var n = 0;
var m = 0;

for( g = 0; g < pd.groups.length; g++ ) {
simple_masks.push( ExpandMods( pd.groups[g].mode_mod, pd.groups[g].masks ) )
index.push(0);
}
do {
var composite = 0;
for( g = 0; g < pd.groups.length; g++ ) {
masks[g] = simple_masks[g][index[g]];
if( no_overlap )
if( composite & masks[g] ) {
break;
}
composite |= masks[g];
}
if( g < pd.groups.length ) {
g++;  // add 1 to g... so 'this' gets incremented
// this faulted, so next iterate.
for( var h = g; h < pd.groups.length; h++ ){
index[h] = 0; // reset all the following counters 
}
}
else
composite_masks.push(composite);
// iterate combination set.
index[g-1]++; 
while( g > 0 && ( index[g-1] >= simple_masks[g-1].length ) ) {
if( g > 1 )  // don't reset 0.
index[g-1] = 0;
if( --g > 0 )
index[g-1]++; 
}
if( !g ){
if( index[0] >= simple_masks[0].length )
break;
}
}while(1);
}


This is all algorithmic; no expression calls a function, so a lot of things 
should be easiliy identifiable as unchanging.

pd.groups.length

for instance comes from 'pd.groups' which will never change during the 
duration of the above code, and that array within it also would not change, 
would the length for that be read once at the start?
I've seen compiled code from C (where many compilers apparently assume that 
everything is at least somewhat volatile (apparently) and reload values of 
partial expressions even though that same value was just computed in the 
previous section.  Especially where the number of available scratch 
registers is plentiful (as opposed to only 4-6) ?

I would hope that I could write visually appealing code like the above and 
have the guts of the actual code generation do all the clever work; maybe 
it is a lot of work to do a pattern match in an AST and find all 
sub-expressions that are exactly the same to coalesce into a single 
access...



-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/e66d6cb7-62b6-4976-bb85-fc9166ad%40googlegroups.com.


Re: [v8-users] MSVC Debug Build

2020-03-11 Thread J Decker
https://github.com/nodejs/node/issues/27189

+  '_ITERATOR_DEBUG_LEVEL=0',


On Wed, Mar 11, 2020 at 1:40 PM Calvin L  wrote:

> Hi,
>
> I was wondering if anyone had any luck with the MSVC debug build so far? I
> successfully built v8 as a static library for release builds with these
> commands
>
> *gn gen out.gn/x64_release 
> --args="is_component_build=false is_debug=false target_cpu=\"x64\"
> v8_enable_pointer_compression=false is_clang=false"*
>
> *call ninja -C out.gn/x64_release *
>
>
> *   gn gen out.gn/x86_release 
> --args="is_component_build=false is_debug=false target_cpu=\"x86\"
> v8_enable_pointer_compression=false is_clang=false"*
> *   call ninja -C out.gn/x86_release *
>
> These compile fine with my project. I haven't been able to get the debug
> build to work on the other hand. Here's some of the args i tried to build
> with
>
> args: is_component_build=false
>  is_debug=true
>  target_cpu="x64"
>  v8_enable_pointer_compression=false
>  is_clang=false
>
> result: successful build failed linking
>
>
> args: is_component_build=false
>  is_debug=true
>  symbol_level=2
>  target_cpu="x64"
>  v8_enable_backtrace=true
>  v8_enable_slow_dchecks=true
>  v8_enable_pointer_compression=false
>  is_clang=false"
>
> result: successful build failed linking
>
>
> args: is_component_build=false
>  is_debug=true symbol_level=2
>  target_cpu="x64"
>  v8_enable_backtrace=true
>  v8_enable_slow_dchecks=true
>  v8_optimized_debug=false
>  v8_enable_pointer_compression=false
>  is_clang=false
>
> result: failed build (attached errors in text file)
>
>
> args: is_component_build=false
>  is_debug=true
>  symbol_level=2
>  target_cpu="x64"
>  v8_enable_backtrace=true
>  v8_enable_slow_dchecks=true
>  v8_optimized_debug=false
>  v8_enable_pointer_compression=false
>  is_clang=false
>  enable_iterator_debugging=true
>
> result: successful build failed link
>
>
> In the cases where the build was successful, I received errors while
> trying to compile with my project
> *"mismatch detected for '_ITERATOR_DEBUG_LEVEL':value '0' doesn't
> match value '2' in {some other .lib in my project}"*
> *"mismatch detected for "RuntimeLibrary": value 'MT_StaticRelease'
> doesn't match value 'MTd_StaticDebug in {**some other .lib in my project*
> *}'*
> does anyone know why this is? Thanks in advanced!
>
> -CL
>
> --
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/e09011e8-a321-4995-bcef-61d109784828%40googlegroups.com
> 
> .
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqU9WPV7KtK8Nq8BHnioOvbqzza%3DyXxskLsoAhMQ_6%2BPfA%40mail.gmail.com.


[v8-users] Catching a promise resolution in C++ (Howto use Then() of Promise)

2019-11-26 Thread J Decker
This is a C++ Node Addon; but after some investigation it might not be a
node-level thing...

I have a event loop that gets an event, which when triggered calls a JS
function.  The JS function returns a promise.  The C++ code needs to just
attach .then and .catch events to the promise, and get called when it is
resolved.  (In this case, C++ is just consuming a promise from JS).

What I get when I add my callbacks (which itself works) and return to the
event worker loop is, later, when resolved...

```

Error from thread: TypeError: Method Promise.prototype.then called on
incompatible receiver undefined
at then ()
/usr/bin/node[232537]: ../src/debug_utils.cc:289:void
node::CheckedUvLoopClose(uv_loop_t*): Assertion `0 && "uv_loop_close()
while having open handles"' failed.
 1: 0x55b21041 node::Abort() [/usr/bin/node]

```

This is the API of A Promise...
https://v8docs.nodesource.com/node-12.0/d3/d8f/classv8_1_1_promise.html#aca2ce1ed00df2f653af444c8f186f3db


it has a Then() function; which I think is to add callbacks?

```
static void acceptResolved(const v8::FunctionCallbackInfo& args ) {
printf( "Reject called on promise...");
}
static void acceptRejected(const v8::FunctionCallbackInfo& args ) {
printf( "Reject called on promise...");
}


//.. This is the call into JS, and getting the result as a promise

MaybeLocal result = cb->Call( context,
eventMessage->_this->_this.Get( isolate ), 1, argv );
if( !result.IsEmpty() ) {
Local ret = result.ToLocalChecked();
Local retPro = ret.As();
if( !retPro.IsEmpty() ){
wssiInternal->acceptEventMessage = eventMessage;
wssiInternal->acceptPromise.Reset( isolate, retPro );
Local promiseResolved =
v8::Function::New(isolate->GetCurrentContext(), acceptResolved, wssi
).ToLocalChecked();
Local promiseRejected =
v8::Function::New(isolate->GetCurrentContext(), acceptRejected, wssi
).ToLocalChecked();

//Then (Local< Context > context, Local< Function > on_fulfilled, Local<
Function > on_rejected)
MaybeLocal retval = retPro->Then( context, promiseResolved,
promiseRejected );
//  TypeError: Method Promise.prototype.then called on incompatible
receiver undefined at then ()

// don't set done, keep blocking the acceptor...
continue;
}
}

```

There wasn't a specific addon example with this; and NAPI just provides
creation and resolution of promises, not catching the resolution of them.
https://github.com/nodejs/node-addon-examples/issues/85#issuecomment-558022938

Someone suggested that I modify the above

```
// get and save the prototype then and catch functions; should be constant?
// save them in a Persistent for later...
if( c->promiseThen.IsEmpty()){
   Local cons = Local::Cast(
 retPro->Get( context, String::NewFromUtf8( isolate, "then",
NewStringType::kNormal ).ToLocalChecked() ).ToLocalChecked());
   c->promiseThen.Reset( isolate, cons );
}
if( c->promiseCatch.IsEmpty()){
   Local cons = Local::Cast(
 retPro->Get( context, String::NewFromUtf8( isolate, "catch",
NewStringType::kNormal ).ToLocalChecked() ).ToLocalChecked());
   c->promiseCatch.Reset( isolate, cons );
}

// and then use...
// ---  MaybeLocal retval = retPro->Then( context,
promiseResolved, promiseRejected );
// +++ ...
Local argv[1] = { promiseResolved };
   Local result = c->promiseThen.Get( isolate )->Call( context,
retPro, 1, argv ).ToLocalChecked();
   argv[0] = { promiseRejected };
   result = c->promiseCatch.Get( isolate )->Call( context, retPro, 1, argv
).ToLocalChecked();
// not that I need result... or to local checked or...

```


Why can't I just use the Then() function?

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqVe-6cErvkkf31ZZ3rD_OG8r5LeMwjDkQiZ3fYy9CXNew%40mail.gmail.com.


Re: [v8-users] Slow interop with native code on arm64

2019-08-01 Thread J Decker
Or it's entirely my fault... sorry

On Thu, Aug 1, 2019 at 10:41 AM J Decker  wrote:

> I'm not sure where/how to address this... so bear with me if this isn't
> JUST V8.
>
> My latest toy is a RK3399 system (
> http://en.t-firefly.com/product/rocrk3399pc )
> I've manged to get the linux image to build, and install a more complete
> development environment, and got Node 13-pre (12.7.0) to build, and my own
> addon.
> I was curious about the JS vs native performance, and I have both JS and C
> versions of many things in a few packages.  The JS performance is pretty
> good, can't fault much there, but then when I ran the same simple tests
> like "parse( '1234' )" to get a number result, the Node Addon (which works
> directly with the V8 library for 99% of the interfacing, just using a few
> convenience macros to build FunctionTemplates)
> I *think* that the conversion from string to String::Utf8Value is
> extra-ordinarily slow.  another test that either passes numbers, or passes
> nothing and gets back arraybuffers(with external storage) and/or Numbers is
> actually very fast.
>
> I don't know how I can create a reproduction, and/or I don't know what to
> really investigate I do have, in the case of the parsin, some
> performance timers around converting from JS to C, doing the parsing, and
> building the values back in JS Engine from C that can narrow it down...
>
> A test that usese the same parser in JS does 4M parsings in 6 seconds, and
> takes the (CMake Debug) build does 2M parsings in 35 seconds, and the CMake
> Release build 27 seconds.  The run times on windows x64 are approximately
> the same (as each other, at about 1 seconds for 4M/2M respectively...
> because getting utf8 values sucks (pardon the slang)).  Single threaded.
>
> --
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/dc1c1cdd-80b4-4f23-ba87-a7ff49610339%40googlegroups.com
> <https://groups.google.com/d/msgid/v8-users/dc1c1cdd-80b4-4f23-ba87-a7ff49610339%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqVXNY8y_k_UjJdxrdE2uXBRxedoEdjZt%3DDTGgR7Mpc%3DnA%40mail.gmail.com.


[v8-users] Slow interop with native code on arm64

2019-08-01 Thread J Decker
I'm not sure where/how to address this... so bear with me if this isn't 
JUST V8.

My latest toy is a RK3399 system ( 
http://en.t-firefly.com/product/rocrk3399pc ) 
I've manged to get the linux image to build, and install a more complete 
development environment, and got Node 13-pre (12.7.0) to build, and my own 
addon.
I was curious about the JS vs native performance, and I have both JS and C 
versions of many things in a few packages.  The JS performance is pretty 
good, can't fault much there, but then when I ran the same simple tests 
like "parse( '1234' )" to get a number result, the Node Addon (which works 
directly with the V8 library for 99% of the interfacing, just using a few 
convenience macros to build FunctionTemplates) 
I *think* that the conversion from string to String::Utf8Value is 
extra-ordinarily slow.  another test that either passes numbers, or passes 
nothing and gets back arraybuffers(with external storage) and/or Numbers is 
actually very fast.

I don't know how I can create a reproduction, and/or I don't know what to 
really investigate I do have, in the case of the parsin, some 
performance timers around converting from JS to C, doing the parsing, and 
building the values back in JS Engine from C that can narrow it down...

A test that usese the same parser in JS does 4M parsings in 6 seconds, and 
takes the (CMake Debug) build does 2M parsings in 35 seconds, and the CMake 
Release build 27 seconds.  The run times on windows x64 are approximately 
the same (as each other, at about 1 seconds for 4M/2M respectively... 
because getting utf8 values sucks (pardon the slang)).  Single threaded.

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/dc1c1cdd-80b4-4f23-ba87-a7ff49610339%40googlegroups.com.


[v8-users] Re: Native Modules

2019-08-01 Thread J Decker
Maybe there's some hints here for how node does it there's very little 
to node that is on the C(++) side...
https://github.com/nodejs/node/tree/master/lib/internal/modules/cjs

https://nodejs.org/api/addons.html
Though that doesn't help actually embedding it.
Although Node does also provide modules like 'os' 'process' ... 


On Wednesday, July 17, 2019 at 1:02:06 PM UTC-7, Joel Scarfone wrote:
>
> How can i embed v8 such that I can provide a native module? For example:
>
> import {foo} from 'FooBar';
>
> foo();
>
>
> How can i get *foo() *to call into native code?
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/0c439fa4-a5c4-49b2-9924-a05eedb76b25%40googlegroups.com.


Re: [v8-users] Is it possible to building v8 v7.5.x from source on Centos 7?

2019-07-24 Thread J Decker
>
> Oh, I did it again, you said V8, Not node... Sorry
>>
>>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqXFm91wHWPHO6SwUYvb0UC1ShQ_mRk%2BrSBPy10na7HTaA%40mail.gmail.com.


Re: [v8-users] Is it possible to building v8 v7.5.x from source on Centos 7?

2019-07-24 Thread J Decker
I realize it's not what you're asking, and maybe you have reason to build
from source, but I'm going to assume this is really what you want...


Unfortunately I didn't save the original source I got this from.
Since CentOS is yum based, and I really hate to drop untracked sources in...

I was stuck with centOS's 6.x (5.x?) version and needed at least 7 (well 8
at that time had just come out when I was migrating)

# removes old node thing from centos
# cleans cache, and makes sure they're ALL gone ( probably not required)

yum remove nodesourc*
yum clean all
rm -fr /var/cache/yum/*

# then really it's just ...
# choose one of the below...
curl -sL https://rpm.nodesource.com/setup_8.x | bash -
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
curl -sL https://rpm.nodesource.com/setup_12.x | bash -

Pretty sure that does the install too; but maybe you need this too...

yum install nodejs

On Wed, Jul 24, 2019 at 3:25 PM Temuri Imnaishvili 
wrote:

> Hi,
>
>
> https://stackoverflow.com/questions/57164363/building-v8-from-source-on-centos-7
>
> How can one build v8 from source on most recent Centos 7?
>
>
> I tried, but ninja build always fails right away with "centos
> /lib64/libc.so.6: version `GLIBC_2.18' not found" message.
>
>
> Plus, dependency installer script tells that Centos platform is not
> supported.
>
>
> So, is there a way?
>
>
> Thanks!
>
> --
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/877ec6d1-ee30-4c60-a8b3-acfe821e5bd6%40googlegroups.com
> 
> .
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqXYiQk93qxTGiqnrLgfUX_e4X1KhedTFMx_if-JNogh%2Bw%40mail.gmail.com.


Re: [v8-users] Re: Using 'this' in scripts

2019-06-21 Thread J Decker
Sorry I did reflect that there's probably cases of simpler expessions.
You could limit it to just no semicolons, and only allow commas, then you
could just put it in a `()=>(/*expression without return*/)`
but that doesn't let you pass a this.

so you could make a  `function() { return ` + (your expression ) + ` } `
could get a 'this'.
In the V8 engine though, args do have 'Holder()' and 'This()' and I'm not
entirely sure how they differ, but most of my code is actually using
Holder() to unwrap and get my object from.


> But; go go back to the start, what value would you want to return from a
> constructor other than the constructed 'this'?
>
>
> On Fri, Jun 21, 2019 at 2:56 AM Zoltan B  wrote:
>
>> Thank you!
>>
>> Also, In the case I'm running a Script (and not a function), if I write
>> "myvariable" or "this.myvariable" then is there a way to distuingish
>> between the two in the C++ side? Currently how I'm using it is like this:
>> The context the script runs in has a global object with my template, so
>> that I can provide external name resolution for contexts. However
>> "myvariable" and "this.myvariable" both call the same global object, so if
>> I could distuingish between the two, I could provide separate name
>> resolution for 'this' and contextual variables.
>>
>> 2019. június 21., péntek 10:01:47 UTC+2 időpontban Caitlin Potter a
>> következőt írta:
>>>
>>> No, that method would still require a return statement. Getting rid of
>>> the return statement requirement would need a new API, or transforming the
>>> source program before using it.
>>>
>>> On Jun 21, 2019, at 3:27 AM, Zoltan B  wrote:
>>>
>>> Thanks for your answer! :)
>>>
>>> In the (1) solution of yours, is there a way to be able to create
>>> functions that behave like scripts? I mean, that if I write onclick="1+1",
>>> then if I parse and run "1+1" as a function it would return 2 without using
>>> the "return" keyword (e.g.: "return 1+1")?
>>>
>>> 2019. június 20., csütörtök 16:04:53 UTC+2 időpontban Caitlin Potter a
>>> következőt írta:

 I don’t believe you can do exactly what you want here, as there are two
 parts:

 1) getting `this` set properly. I believe you should be able to use
 `CompileFunctionInContext()` to this effect, which is used to provide
 implicit arguments to DOM onxxx=“script...” handlers. I believe you can
 then make `this` whatever you want in that function. Return statements
 would still be legal, as they are in DOM events, though.

 2) completion value of the script. This is trickier, as the v8 API does
 not expose a way to run the AST rewriter on arbitrary functions afaict. It
 may be possible to introduce an API for this, if it’s important.

 You might be able to take a third option, transforming the code with a
 custom Babel plugin before passing it to v8 (at runtime), and providing the
 sourcemap info along with it for debugging purposes.

 On Jun 20, 2019, at 9:49 AM, Zoltan B  wrote:

 Any ideas? :)

 2019. június 7., péntek 13:16:08 UTC+2 időpontban Zoltan B a következőt
 írta:
>
> Hi!
>
> Is there a way to provide value for the 'this' keyword, when I'm
> running a v8 Script?
>
> An alternative would be to compile the code as a function instead, and
> provide 'this' when calling it trough 'recv', but then I would have other
> issues: running a script like this: "1+1" would not return 2 as a result,
> as I would have to explicitly put a "return" in front of "1+1", so the
> function will return the script's value. This seems to be error prone, not
> to mention that script locations will skew when viewed from DevTools. 
> Using
> "return eval('1+1')" would work, but it kills performance due to the eval.
>
> --
 --
 v8-users mailing list
 v8-u...@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-u...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/v8-users/746a4d9f-d364-4506-8783-347eee5dad6c%40googlegroups.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

 --
>>> --
>>> v8-users mailing list
>>> v8-u...@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-u...@googlegroups.com.
>>> To view this discussion on the web visit
>>> 

Re: [v8-users] Re: Using 'this' in scripts

2019-06-21 Thread J Decker
I run scripts to extend a 'this', but when that script runs, it just
iniializes this.whatever and provides methods like this.handleMessage =
function() {}

If I want the object initilaized with the script to give me a value, I'd
call a method on the this, but I don't know that the initialization code
would really return any value.  Maybe I'm just biased because I consider
that script a 'constructor()' which doesn't return, but instead just
defines the methods on the object specified

   var objectForThis = {};
   var script = "   \
this.method = ()=>{\
console.log( "stuff" );\
   return 6+3; \
 }; \
var closureVariablesWorkToo = 33; "

var f = new Function( /* function args */ "JSON", "localStorage",
script );
f.call( objectForThis, JSON, localStorage /*, ... extra args */ );

var result1 =   objectForThis.method();



//    This might be a way of providing getter and setter on the 'this'
so you can know if 'myvariable' is accessed...

   var anotherScript = `
   const scriptMethods = {
method() {
console.log( "stuff" );
   return 6+3;
 },
 get Getter() {
 return 'getter value';
 },
 set Getter(val) {
 console.log( 'save setter value' );
 }
   };

  Object.defineProperties( this, Object.getOwnPropertyDescriptors(
scriptMethods ));  ";


But; go go back to the start, what value would you want to return from a
constructor other than the constructed 'this'?


On Fri, Jun 21, 2019 at 2:56 AM Zoltan B  wrote:

> Thank you!
>
> Also, In the case I'm running a Script (and not a function), if I write
> "myvariable" or "this.myvariable" then is there a way to distuingish
> between the two in the C++ side? Currently how I'm using it is like this:
> The context the script runs in has a global object with my template, so
> that I can provide external name resolution for contexts. However
> "myvariable" and "this.myvariable" both call the same global object, so if
> I could distuingish between the two, I could provide separate name
> resolution for 'this' and contextual variables.
>
> 2019. június 21., péntek 10:01:47 UTC+2 időpontban Caitlin Potter a
> következőt írta:
>>
>> No, that method would still require a return statement. Getting rid of
>> the return statement requirement would need a new API, or transforming the
>> source program before using it.
>>
>> On Jun 21, 2019, at 3:27 AM, Zoltan B  wrote:
>>
>> Thanks for your answer! :)
>>
>> In the (1) solution of yours, is there a way to be able to create
>> functions that behave like scripts? I mean, that if I write onclick="1+1",
>> then if I parse and run "1+1" as a function it would return 2 without using
>> the "return" keyword (e.g.: "return 1+1")?
>>
>> 2019. június 20., csütörtök 16:04:53 UTC+2 időpontban Caitlin Potter a
>> következőt írta:
>>>
>>> I don’t believe you can do exactly what you want here, as there are two
>>> parts:
>>>
>>> 1) getting `this` set properly. I believe you should be able to use
>>> `CompileFunctionInContext()` to this effect, which is used to provide
>>> implicit arguments to DOM onxxx=“script...” handlers. I believe you can
>>> then make `this` whatever you want in that function. Return statements
>>> would still be legal, as they are in DOM events, though.
>>>
>>> 2) completion value of the script. This is trickier, as the v8 API does
>>> not expose a way to run the AST rewriter on arbitrary functions afaict. It
>>> may be possible to introduce an API for this, if it’s important.
>>>
>>> You might be able to take a third option, transforming the code with a
>>> custom Babel plugin before passing it to v8 (at runtime), and providing the
>>> sourcemap info along with it for debugging purposes.
>>>
>>> On Jun 20, 2019, at 9:49 AM, Zoltan B  wrote:
>>>
>>> Any ideas? :)
>>>
>>> 2019. június 7., péntek 13:16:08 UTC+2 időpontban Zoltan B a következőt
>>> írta:

 Hi!

 Is there a way to provide value for the 'this' keyword, when I'm
 running a v8 Script?

 An alternative would be to compile the code as a function instead, and
 provide 'this' when calling it trough 'recv', but then I would have other
 issues: running a script like this: "1+1" would not return 2 as a result,
 as I would have to explicitly put a "return" in front of "1+1", so the
 function will return the script's value. This seems to be error prone, not
 to mention that script locations will skew when viewed from DevTools. Using
 "return eval('1+1')" would work, but it kills performance due to the eval.

 --
>>> --
>>> v8-users mailing list
>>> v8-u...@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 

Re: [v8-users] main function in V8

2019-06-03 Thread J Decker
On Mon, Jun 3, 2019 at 11:18 AM TL  wrote:

> This question might sound weird to some of you, but
> I'm wondering whether there is a main function in V8 as it is written in
> C++.
> If it does, which source file does this main function lives?
>
> V8, no.  There's a Shell D8 https://v8.dev/docs/d8 that google uses.


> Thank you.
>
> --
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/e6d7f57d-088f-4990-802c-1134951c9317%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAA2GJqWkNyVK9j%3DeeuWwkqdQhKm%2BKWC_hkaOCOt%2BwmgDewvvrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] V8 ->JS Emscripten Compatibility interface?

2019-05-28 Thread J Decker
I don't suppose anyone has a stub of maybe V8.h for compatibility with 
emscripten/ wasm that maybe handles things through EM_JS() or EM_ASM()? 

I sorta spent a lot of time writing V8->C bindings for various Node addon 
functionality (it has very little to do with node though, since I write it 
without NaN) 

I do a lot of common simple things like Object::New(), ->Set, ->Get, ... 
(kind of indexing how much complexity this actually would be), 
ArrayBuffers/TypedArrays, object prototype definitions... there's even some 
accessors in some of the prototypes... strings, numbers, (dates with a 
hack, would be easier with an EM_JS() maybe?), bignums; some 
Eternals,...

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/8ac2a40a-77bb-41b5-b993-5dd41c83691e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] V8 node js

2019-04-02 Thread J Decker
windows is built with visual studio tools anyway;
Build node (totally off topic BTW) load it in visual studio with F5 to run
it.,

On Tue, Apr 2, 2019 at 2:17 PM Marto Parts  wrote:

> I will isntall gdb but on windows it is a complete mess
>
> Il giorno mar 2 apr 2019 alle ore 22:36 J Decker  ha
> scritto:
>
>> okay you can either use gdb or lldb  'gdb --args node 

Re: [v8-users] V8 node js

2019-04-02 Thread J Decker
okay you can either use gdb or lldb  'gdb --args node 

Re: [v8-users] V8 node js

2019-04-02 Thread J Decker
start node with --inspect-brk  (or --inspect)
open chrome go to 'chrome://inspect'  and the node process should show up
in the list of things to debug ?

On Tue, Apr 2, 2019 at 12:49 PM  wrote:

> Does anybody know how to debug v8 (memory/function calls etc ..) but
> running V8 with node js ?
>
> --
> --
> 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] Calling wasm-compiled Functions from C++

2019-02-25 Thread J Decker
On Mon, Feb 25, 2019 at 5:12 PM 'Steven Johnson' via v8-users <
v8-users@googlegroups.com> wrote:

> I'm experimenting with embedding V8 in a test app in order to load,
> compile, and run wasm bytecode that has been generated by LLVM (using V8
> 7.4.x and recent trunk versions of LLVM)
>
> Loading and running seems simple enough
> (via WasmModuleObject::DeserializeOrCompile), but calling the resulting
> functions from C++ seems tricky, because, well, it's not clear that there's
> a public V8 API for actually looking at what's in the resulting
> WasmModuleObject; in JavaScript, you can apparently do something like
>
> let module = new WebAssembly.Module(buffer)
> let imports = { ... map of funcs that are declared as 'import' by
> the module, if any ... }
> let instance = new WebAssembly.Instance(module, imports);
> let myfunc = instance.exports["myfunc"];
> myfunc(...);
>
> but a similar API doesn't seem to be surfaced for C++, at least not in the
> public API.
>
> I've tried replicating the JavaScript calls from C++, but there's a big
> problem: it appears that the 'imports' argument is required to be
> v8::internal::Handle, which (AFAICT) there isn't
> a clean way to create and manipulate directly from the C++ API, at least
> certainly not from the public API:
>
> Local module =
> WasmModuleObject::DeserializeOrCompile(
> isolate, {nullptr, 0}, {source, source_len}).ToLocalChecked();
>
> v8::internal::Handle imports = ???;  //
> Oh well
> Local args[2] = { module, imports };
>
> Local module_instance_exports = context->Global()
> ->Get(context, String::NewFromUtf8(isolate,
> "WebAssembly")).ToLocalChecked().As()
> ->Get(context, String::NewFromUtf8(isolate,
> "Instance")).ToLocalChecked().As()
> ->CallAsConstructor(context, 2,
> args).ToLocalChecked().As()
> ->Get(context, String::NewFromUtf8(isolate,
> "exports")).ToLocalChecked().As()
> ;
>
> I suppose I could accomplish this by adding some extra JS-only wrapper
> code that does the necessary magic, but that's going to add another layer
> of indirection that surely shouldn't be necessary here (since the code in
> question here is otherwise free of JavaScript).
>
> The thing that makes this extra-fun is that apparently LLVM injects a
> couple of symbols into the import table of every bit of wasm it generates
> ("__linear_memory" and "__indirect_function_table")... which don't appear
> to be referenced in any code in V8 that I can find, so their purpose is a
> bit of a mystery to me. (Perhaps holdovers from older implementations of
> wasm?) In any event, I'm almost certainly going to have other imports I
> need to fill in here (for glue functions), so figuring out how to to
> accomplish this is probably essential to my task.
>
> So...
>
> (1) Is there an explicit API to access/call wasm-compiled functions from
> C++? Is so, where may I find it? If not, um, shouldn't we have one?
> (2) If there isn't a C++ API for this (and/or isn't going to be one
> anytime in the very near future), is the above approach the most reasonable
> workaround for now?
>


> (3) If the above mimic-JS-from-C++ approach is reasonable, is there a
> clean way to specify the imports table?
> (4) Finally, just out of curiosity, anyone know what the story is with
> "__linear_memory" and "__indirect_function_table"?
>
I'm not familiar with these, but do know about HEAP8, HEAP32, etc. :)  The
code I get generated does not have either of those symbols; it might be to
support some C++ structure you have... All the code I compiled was actually
C. The basic C library support all works as expected (fopen for instance).


>
> Was far as I know, the WASM code is basically self contained and doesn't
> immediately provide interface with javascript.
>

I used WASM and compiled a GSM codec (audio).
THis is the script I used to build it...
There's several options to export functions for JS to call.  The batch file
includes
`-s EXPORTED_FUNCTIONS="['_gsm_create','_gsm_decode','_gsm_encode']"`

https://github.com/d3x0r/gsm/blob/master/x.bat

The readme here shows basically how to use _gsm_create, _gsm_decode and
_gsm_encode.
https://github.com/d3x0r/gsm-wasm

To get JS arrays/strings into the WASM code you need to malloc in the wasm
heap, and copy the data to the buffers; primitive values (numbers/strings)
pass through simply enough.

And yes, there is very bad support for inter-oping the other direction; The
other thing I was playing with WASMing is a JSOX(JSON variant) parser, but
creating the objects on the .parse() side of things is very hairy.

But most of these issues would be Emscripten; since WASM has to interop
with other JS engines, and not just V8.


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

Re: [v8-users] Re: [blink-dev] Re: [v8-dev] Intent to ship: Private class fields

2019-02-21 Thread J Decker


On Thursday, February 21, 2019 at 5:02:35 AM UTC-8, Mathias Bynens wrote:
>
> The v8-users mailing list is not the best place to discuss the design of 
> new ECMAScript language features. This proposal reached Stage 3 of the 
> TC39 process <https://tc39.github.io/process-document/> a long time ago, 
> and each design decision has since been revisited and reaffirmed during 
> TC39 meetings. It’s time to ship it.
>
> On Thu, Feb 21, 2019 at 1:07 PM J Decker > 
> wrote:
>
>> class xyz {
>> x = isTrueFalse();
>> #y = !x;
>> }
>>
>> that would work in a class though?
>>
>
> The `x` in `#y = !x` would refer to the global `x` in this example. You 
> probably meant to refer to the `x` field above, which you can accomplish 
> with `#y = !this.x`.
>
> Okay I understand then.

>
>
>>
>>> On Wed, Feb 20, 2019 at 5:14 PM Adam Klein >> > wrote:
>>>
>>>> LGTM!!
>>>>
>>>> On Wed, Feb 20, 2019 at 12:20 PM 'Mathias Bynens' via blink-dev <
>>>> blin...@chromium.org > wrote:
>>>>
>>>>> LGTM
>>>>>
>>>>> On Wed, Feb 20, 2019 at 8:58 PM Sathya Gunasekaran <
>>>>> gsa...@chromium.org > wrote:
>>>>>
>>>>>> Contact Emails
>>>>>>
>>>>>> gsa...@chromium.org 
>>>>>>
>>>>>>
>>>>>> Spec
>>>>>>
>>>>>> https://github.com/tc39/proposal-class-fields
>>>>>>
>>>>>>
>>>>>> Summary (taken from our WebFu article 
>>>>>> <https://developers.google.com/web/updates/2018/12/class-fields>)
>>>>>>
>>>>>>  
>>>>>>
>>>>>> This private fields proposal provides encapsulation: If you're using 
>>>>>> an instance of a class, you cannot reference that class's private fields 
>>>>>> from outside the class body. You can only reference private fields from 
>>>>>> within the class that defines them.
>>>>>>
>>>>>>
>>>>>> The new private fields syntax is similar to public fields, except you 
>>>>>> mark the field as being private by using # 
>>>>>> <https://github.com/tc39/proposal-class-fields/blob/master/PRIVATE_SYNTAX_FAQ.md>.
>>>>>>  
>>>>>> You can think of the # as being part of the field name:
>>>>>>
>>>>>>
>>>>>> class IncreasingCounter {
>>>>>>
>>>>>>  #count = 0;
>>>>>>
>>>>>>  get value() {
>>>>>>
>>>>>>console.log('Getting the current value!');
>>>>>>
>>>>>>return this.#count;
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  increment() {
>>>>>>
>>>>>>this.#count++;
>>>>>>
>>>>>>  }
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Private fields are not accessible outside of the class body:
>>>>>>
>>>>>>
>>>>>> const counter = new IncreasingCounter();
>>>>>>
>>>>>> counter.#count;
>>>>>>
>>>>>> // → SyntaxError
>>>>>>
>>>>>> counter.#count = 42;
>>>>>>
>>>>>> // → SyntaxError
>>>>>>
>>>>>>
>>>>>> This intent to ship includes private static fields as well:
>>>>>>
>>>>>>
>>>>>> class ClassCounter {
>>>>>>
>>>>>>  static #count = 0;
>>>>>>
>>>>>>  static increment() {
>>>>>>
>>>>>>this.#count++;
>>>>>>
>>>>>>  }
>>>>>>
>>>>>> }
>>>>>>
>>>>>> ClassCounter.#count;
>>>>>>
>>>>>> // → SyntaxError
>>>>>>
>>>>>> ClassCounter.increment(); 
>>>>>>
>>>>>>
>>>>>>
>>>>>> Interoperability and compatibility risk
>>>>>>
>>>>>> This stage 3 proposal introduces new syntax that was previousl

Re: [v8-users] Re: [blink-dev] Re: [v8-dev] Intent to ship: Private class fields

2019-02-21 Thread J Decker
class xyz {
x = isTrueFalse();
#y = !x;
}

that would work in a class though?


> On Wed, Feb 20, 2019 at 5:14 PM Adam Klein  wrote:
>
>> LGTM!!
>>
>> On Wed, Feb 20, 2019 at 12:20 PM 'Mathias Bynens' via blink-dev <
>> blink-...@chromium.org> wrote:
>>
>>> LGTM
>>>
>>> On Wed, Feb 20, 2019 at 8:58 PM Sathya Gunasekaran 
>>> wrote:
>>>
 Contact Emails

 gsat...@chromium.org


 Spec

 https://github.com/tc39/proposal-class-fields


 Summary (taken from our WebFu article
 )



 This private fields proposal provides encapsulation: If you're using an
 instance of a class, you cannot reference that class's private fields from
 outside the class body. You can only reference private fields from within
 the class that defines them.


 The new private fields syntax is similar to public fields, except you
 mark the field as being private by using #
 .
 You can think of the # as being part of the field name:


 class IncreasingCounter {

  #count = 0;

  get value() {

console.log('Getting the current value!');

return this.#count;

  }

  increment() {

this.#count++;

  }

 }


 Private fields are not accessible outside of the class body:


 const counter = new IncreasingCounter();

 counter.#count;

 // → SyntaxError

 counter.#count = 42;

 // → SyntaxError


 This intent to ship includes private static fields as well:


 class ClassCounter {

  static #count = 0;

  static increment() {

this.#count++;

  }

 }

 ClassCounter.#count;

 // → SyntaxError

 ClassCounter.increment();



 Interoperability and compatibility risk

 This stage 3 proposal introduces new syntax that was previously a
 SyntaxError. There’s very low web compat risk.


 Firefox: In development
 

 Safari: In development 

 Edge: No signals


 Is this feature fully tested?



 Yes, this feature passes V8’s own mjsunit/cctest tests as well as all
 the Test262 tests.


 Tracking bug

 v8:5368 



 Link to entry on the Chrome Platform Status dashboard

 https://www.chromestatus.com/feature/6035156464828416



 Requesting approval to ship?

 Yes. Note that since this is a V8/JS feature, this post is just an FYI
 to blink-dev — no sign off from Blink API owners is required.



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

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "blink-dev" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADizRgaQiv2%3DmEtPOcprwkGg_KcxCfF7A%3DpPp6q-kCW%3DGN2Mtw%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> --
>> 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] Re: [blink-dev] Re: [v8-dev] Intent to ship: Private class fields

2019-02-21 Thread J Decker
Yay!
Oh wait...
really?  You have to use an expression syntax to define a class data
member?   instead of the existing obhect field definition?

class xyz {
x = 0;
y = 0;
add() { }
/* Oh I see; there's no punctuation between class methods */
sub() { }
}


rather than

class xyz {
x:0,
y: 0
add() {} /* , optional? */
sub() {}
}

I'm sure there's method to what I now consider madness...  out

On Wed, Feb 20, 2019 at 5:14 PM Adam Klein  wrote:

> LGTM!!
>
> On Wed, Feb 20, 2019 at 12:20 PM 'Mathias Bynens' via blink-dev <
> blink-...@chromium.org> wrote:
>
>> LGTM
>>
>> On Wed, Feb 20, 2019 at 8:58 PM Sathya Gunasekaran 
>> wrote:
>>
>>> Contact Emails
>>>
>>> gsat...@chromium.org
>>>
>>>
>>> Spec
>>>
>>> https://github.com/tc39/proposal-class-fields
>>>
>>>
>>> Summary (taken from our WebFu article
>>> )
>>>
>>>
>>>
>>> This private fields proposal provides encapsulation: If you're using an
>>> instance of a class, you cannot reference that class's private fields from
>>> outside the class body. You can only reference private fields from within
>>> the class that defines them.
>>>
>>>
>>> The new private fields syntax is similar to public fields, except you
>>> mark the field as being private by using #
>>> .
>>> You can think of the # as being part of the field name:
>>>
>>>
>>> class IncreasingCounter {
>>>
>>>  #count = 0;
>>>
>>>  get value() {
>>>
>>>console.log('Getting the current value!');
>>>
>>>return this.#count;
>>>
>>>  }
>>>
>>>  increment() {
>>>
>>>this.#count++;
>>>
>>>  }
>>>
>>> }
>>>
>>>
>>> Private fields are not accessible outside of the class body:
>>>
>>>
>>> const counter = new IncreasingCounter();
>>>
>>> counter.#count;
>>>
>>> // → SyntaxError
>>>
>>> counter.#count = 42;
>>>
>>> // → SyntaxError
>>>
>>>
>>> This intent to ship includes private static fields as well:
>>>
>>>
>>> class ClassCounter {
>>>
>>>  static #count = 0;
>>>
>>>  static increment() {
>>>
>>>this.#count++;
>>>
>>>  }
>>>
>>> }
>>>
>>> ClassCounter.#count;
>>>
>>> // → SyntaxError
>>>
>>> ClassCounter.increment();
>>>
>>>
>>>
>>> Interoperability and compatibility risk
>>>
>>> This stage 3 proposal introduces new syntax that was previously a
>>> SyntaxError. There’s very low web compat risk.
>>>
>>>
>>> Firefox: In development
>>> 
>>>
>>> Safari: In development 
>>>
>>> Edge: No signals
>>>
>>>
>>> Is this feature fully tested?
>>>
>>>
>>>
>>> Yes, this feature passes V8’s own mjsunit/cctest tests as well as all
>>> the Test262 tests.
>>>
>>>
>>> Tracking bug
>>>
>>> v8:5368 
>>>
>>>
>>>
>>> Link to entry on the Chrome Platform Status dashboard
>>>
>>> https://www.chromestatus.com/feature/6035156464828416
>>>
>>>
>>>
>>> Requesting approval to ship?
>>>
>>> Yes. Note that since this is a V8/JS feature, this post is just an FYI
>>> to blink-dev — no sign off from Blink API owners is required.
>>>
>>>
>>>
>>> --
>>> --
>>> v8-dev mailing list
>>> v8-...@googlegroups.com
>>> http://groups.google.com/group/v8-dev
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-dev" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to v8-dev+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "blink-dev" group.
>> To view this discussion on the web visit
>> https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADizRgaQiv2%3DmEtPOcprwkGg_KcxCfF7A%3DpPp6q-kCW%3DGN2Mtw%40mail.gmail.com
>> 
>> .
>>
> --
> --
> 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] I'm getting a bunch of warnings...

2018-11-04 Thread J Decker
I don't really know how to decode where the actual error is in this chain
of error messages; maybe someone can help?  Maybe I just need to turn on
ignoring the warnings?


WasmStreaming  is V8_EXPORT ; USING_V8_SHARED is defined as 1
WasmStreamingImpl  is V8_EXPORT

#elif USING_V8_SHARED
# define V8_EXPORT __declspec(dllimport)

1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(4494):
warning C4251: 'v8::WasmStreaming::impl_': class
'std::unique_ptr>'
needs to have dll-interface to be used by clients of class
'v8::WasmStreaming'

(This Line)
  std::unique_ptr impl_;

1>with
1>[
1>_Ty=v8::WasmStreaming::WasmStreamingImpl
1>]
1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(4461):
note: see declaration of
'std::unique_ptr>'

(This line)
WasmStreaming(std::unique_ptr impl);

1>with
1>[
1>_Ty=v8::WasmStreaming::WasmStreamingImpl
1>]
1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(4536):
warning C4251: 'v8::WasmModuleObjectBuilderStreaming::promise_': class
'v8::Persistent>'
needs to have dll-interface to be used by clients of class
'v8::WasmModuleObjectBuilderStreaming'

This line
Persistent> promise_;

Persistent is NOT V8_EXPORT; nor promsie nor CopyablePersistentTraits...
they are template classes

1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(4536):
note: see declaration of
'v8::Persistent>'


1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(4540):
warning C4251: 'v8::WasmModuleObjectBuilderStreaming::streaming_decoder_':
class 'std::shared_ptr' needs to have
dll-interface to be used by clients of class
'v8::WasmModuleObjectBuilderStreaming'

(Thsi Line)
   std::shared_ptr streaming_decoder_;
(which is in) class V8_EXPORT WasmModuleObjectBuilderStreaming final {

class StreamingDecoder;

and streamingdecoder is only an opaque class and not V8_EXPORT

1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(4540):
note: see declaration of
'std::shared_ptr'


1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(9224):
warning C4251:
'v8::Context::BackupIncumbentScope::backup_incumbent_context_': class
'v8::Local' needs to have dll-interface to be used by clients
of class 'v8::Context::BackupIncumbentScope'
1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(1310):
note: see declaration of 'v8::Local'


---
I can get these to go away removing V8_EXPORTs also

--- class V8_EXPORT WasmModuleObjectBuilderStreaming final {
+++ class WasmModuleObjectBuilderStreaming final {

--- class V8_EXPORT WasmStreaming final {
+++ class WasmStreaming final {


1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(9224):
warning C4251:
'v8::Context::BackupIncumbentScope::backup_incumbent_context_': class
'v8::Local' needs to have dll-interface to be used by clients
of class 'v8::Context::BackupIncumbentScope'
1>c:\users\panther\.cmake-js\node-x64\v11.0.0\include\node\v8.h(1310):
note: see declaration of 'v8::Local'
1>Done building project "sack_vfs.vcxproj".


---  class V8_EXPORT BackupIncumbentScope {
+++  class BackupIncumbentScope {

-- 
-- 
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] V8 type for ObjectId

2018-10-15 Thread J Decker
when is there an object id in JS?
When would you use it?
I've not encountered objectID.
https://www.npmjs.com/package/sack.vfs (has a JSON thing in there)



On Mon, Oct 15, 2018 at 7:13 AM  wrote:

> I want to do binginds in NodeJS for my C++ code. I use V8 to do it. I
> return a bson class in C++ to an object in JS. I'm using type of V8 to
> get my fields typed in the JS Object.
>
>
> Example for date :
>
> int64_t time = bson_iter_date_time(iter); return Date::New(isolate, time);
>
>
> I don't find a type in C++ V8 for get an ObjectId in my JS object.
>
> --
> --
> 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] Check failed: Handle not reset in first callback. How to Reset my Persistent

2018-10-09 Thread J Decker
On Tue, Oct 9, 2018 at 4:40 PM Mike Moening  wrote:

> The example was helpful.   Encapsulating the Persistent in the callacks
> private data object seems to be the way to roll.
>
>
>> // kParameter will pass a void* parameter back to the callback,
>> kInternalFields
>> // will pass the first two internal fields back to the callback,
>> kFinalizer
>> // will pass a void* parameter back, but is invoked before the object is
>> // actually collected, so it can be resurrected. In the last case, it is
>> not
>> // possible to request a second pass callback.
>> enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
>
>
> Does that help?
>
> Sorry, but no not really.
> Resurrection?  Sounds like a zombie movie (I probably don't need this)
> *kInternalFields - will pass the first two internal fields back to the
> callback*
>

This would be useful in a Node world, there is a utiility class ObjectWrap
which uses 1 internal field to store the user's class reference (the C++
object to be wrapped in a V8/JS reference).  It could use kInternalFields
type instead of duplicating the value to be passed as a parameter.  (Just a
possible application of that)


>
> How? Why?
>
> There has to be something better that explains the callbacks better.
>

I did this originally to track array buffer content, so I can release the
backing buffer when the typed array evaporates (is garbage collected).
I generalized to object mostly later, but then re-added 'strings' for short
lived strings associated with address/connection objects.

---
struct arrayBufferHolder  {
void *buffer; // resources associated with object
Persistent o;
/*
// other types that this might hold add deallocation handlers in
callback
Persistent s;
Persistent ab;
*/
};
typedef struct arrayBufferHolder ARRAY_BUFFER_HOLDER, *PARRAY_BUFFER_HOLDER;


/* GetHolder() returns a holder from a pool; or allocates a new one... it
reuses previous holders*/



/* ... buf and len are the backing
buffer and length of that buffer */
Local arrayBuffer = ArrayBuffer::New( isolate, buf, len );
PARRAY_BUFFER_HOLDER holder = GetHolder();
holder->o.Reset( isolate, arrayBuffer );
holder->o.SetWeak( holder, releaseBuffer,
WeakCallbackType::kParameter );
holder->buffer = buf;



/* The callback to release associated resources when `arrayBuffer` is
collcted */

void releaseBuffer( const WeakCallbackInfo  ) {
PARRAY_BUFFER_HOLDER holder = info.GetParameter();

if( !holder->o.IsEmpty() ) { // in case this is one of 3 types to release.
holder->o.ClearWeak();
holder->o.Reset();
}
Deallocate( void*, holder->buffer ); // your resource deallocation here
DropHolder( holder );  // returns holder to pool for later use. (delete
holder;?)
}

---




> --
> --
> 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] Arraybuffer

2018-09-24 Thread J Decker
On Mon, Sep 24, 2018 at 2:18 PM dan Med  wrote:

> When is it called ?
>
It never is; It doesn't even exist in V8.

>
> On Thu, 20 Sep 2018 at 07:03, dan Med  wrote:
>
>> Ok but then can someone give me a big picture of the directories ? And
>> how the code is generally structured ?
>> Or how is ArrayBufferBuilder:append called ?
>>
>> On Thu, 20 Sep 2018 at 00:14, Peter Schow  wrote:
>>
>>> On Wed, Sep 19, 2018 at 2:36 PM dan Med  wrote:
>>> > This is how I see it atm
>>> > Each tab is a process that is composed of several threads, this
>>> process is sandboxed with the Windows kernel security ( on Windows )
>>> > Then we have WebKit which is the rendered thread inside of this main
>>> tab (thread) which as the name implies will render the page.
>>> > When in the renderer process is v8 called ?
>>> > Or when WebKit is executing UI things v8 is also running JavaScript
>>> code ?
>>>
>>> This mailing list is about V8 itself, not arbitrary consumers (there
>>> are many) of V8.  Do you understand the difference?  V8 has no notion
>>> of "tabs", "WebKit", "renderer process", or "UI".  I suggest you find
>>> another place to ask your questions.
>>>
>>> --
>>> --
>>> 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] BigInt from String?

2018-09-16 Thread J Decker
On Sat, Sep 15, 2018 at 10:38 PM Jakob Kummerow 
wrote:

> To create arbitrary BigInts via the C++ API, use BigInt::NewFromWords.
>
maybe this is a new method; it wasn't available, and would require
preparsing to get an array of native values.


>
> An alternative, as you suggest, is to parse the string as source, because
> "BigInt strings with 'n' suffixes" are BigInt literals. Instead of "eval",
> the API functions to do that are Script::Compile and Script::Run. Look at
> samples/shell.cc or test/cctest/* for examples.
>

That works simply enough.
Would still have just preferred to have like ::NewFromUtf8 methods on Date
and BigInt; this seems like a LOT more overhead.

case JSOX_VALUE_BIGINT:
// just pass the string as is.
script = Script::Compile( String::NewFromUtf8( revive->isolate,
val->string, NewStringType::kNormal, val->stringLen ).ToLocalChecked()
, String::NewFromUtf8( revive->isolate, "BigIntFormater",
NewStringType::kInternalized ).ToLocalChecked() );
result = script->Run();
break;
case JSOX_VALUE_DATE:
char buf[64];
snprintf( buf, 64, "new Date('%s')", val->string );
script = Script::Compile( String::NewFromUtf8( revive->isolate, buf,
NewStringType::kNormal ).ToLocalChecked()
, String::NewFromUtf8( revive->isolate, "DateFormater",
NewStringType::kInternalized ).ToLocalChecked() );
result = script->Run();
break;


> Another alternative, depending on your requirements, might be to create
> this custom "parser" (more of a wrapper, really) in JavaScript:
>

> function MyBigInt(str) {
>   console.assert(str.endsWith("n"));
>   return BigInt(str.substring(0, str.length - 1));
> }
>
>
> On Sat, Sep 15, 2018 at 8:44 PM J Decker  wrote:
>
>>
>>
>> On Sat, Sep 15, 2018 at 8:41 PM J Decker  wrote:
>>
>>> I was implementing a parser that includes BigInt strings with 'n'
>>> suffixes...
>>> I tried to create a BigInt::New( isolate, ...  and then found the only
>>> constructor takes an int64; which isn't a very big int.
>>>
>>> howto bigint from string?
>>>
>>
>> maybe someone could share a snippet to call eval()?  Also Date::New()
>> doesn't take a string :(
>>
>>
>>> --
>>> --
>>> 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] BigInt from String?

2018-09-15 Thread J Decker
On Sat, Sep 15, 2018 at 8:41 PM J Decker  wrote:

> I was implementing a parser that includes BigInt strings with 'n'
> suffixes...
> I tried to create a BigInt::New( isolate, ...  and then found the only
> constructor takes an int64; which isn't a very big int.
>
> howto bigint from string?
>

maybe someone could share a snippet to call eval()?  Also Date::New()
doesn't take a string :(


> --
> --
> 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] BigInt from String?

2018-09-15 Thread J Decker
I was implementing a parser that includes BigInt strings with 'n' 
suffixes...
I tried to create a BigInt::New( isolate, ...  and then found the only 
constructor takes an int64; which isn't a very big int.

howto bigint from string?

-- 
-- 
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] Arraybuffer

2018-09-13 Thread J Decker
On Thu, Sep 13, 2018 at 9:21 AM dan Med  wrote:

> Still no one ?
>
I dont know how I could have been more clear about the memory.
https://groups.google.com/d/msg/v8-users/MNpTNiRaBmM/Muz5-KHpBgAJ

Why do you think there is some magic to the buffer of an arraybuffer?  It's
just continuous bytes in memory.  Especially well suited for communicating
arrays of data to WebGL.


> On Thu, 13 Sep 2018 at 16:31, dan Med  wrote:
>
>> Okay I will but, how could I be sure when blink on the renderer process
>> executes arraybufferbuilder ??
>> Or one more thing, can u redirect me to checkout how v8 represents data
>> in memory, how would it handle arraybuffers?
>> The only thing I’ve managed to find ( in the github repo ) was a
>> JavaScript file which contained if I remember correctly, 2 definitions of
>> sorting algorithms.
>>
>> On Thu, 13 Sep 2018 at 16:23, @soylentgraham 
>> wrote:
>>
>>> You seem to be purposely ignoring the responses to your questions.
>>>
>>> If you still want help, build v8, build a program, breakpoint the
>>> function you want to see is called, debug it (this alone answers all your
>>> questions), then come back if you still have a VERY SPECIFIC question.
>>>
>>>
>>> On Thursday, 13 September 2018 15:15:03 UTC+1, dan Med wrote:

 No one is willingly to help me  ?

 On Wed, 12 Sep 2018 at 20:34, dan Med  wrote:

> Yeah i meant   ArrayBuffer*Builder*::Append my bad but when it is
> actually called in blink ?
> Cause by the name it has to do with Arraybuffers..
> Plus if i build v8 so i can examine the memory layout, where is the
> code on how v8 handeles arraybuffer ?
> Where is the doc or some source where there's explained how v8
> represents object in memory, how can i be sure that in memory i'm not
> starrying at a pointer instead of an object or something like that...
>
> Il giorno mer 12 set 2018 alle ore 19:40 Jakob Kummerow <
> jkum...@chromium.org> ha scritto:
>
>> On Wed, 12 Sep 2018 at 13:15, dan Med  wrote:
>>
>>> But can someone help me understand the arraybuffer part ? How to
>>> call arraybuffer::append and when I create an instance of a arraybuffer 
>>> it
>>> will create it with maximum size so 37... bytes and will only say that 
>>> the
>>> bytes used are the one which I’ve declared ?
>>>
>>
>> There is no ArrayBuffer::Append. Read closely: you've found
>> ArrayBuffer*Builder*::Append, which is some implementation detail in
>> Blink (not V8). I don't know when it's called, but I've pointed out 
>> before
>> how you can find out. When you use ArrayBuffer objects in JavaScript, 
>> then
>> that code is not executed at all.
>>
>> And when you create an ArrayBuffer(10) in JavaScript, it definitely
>> does not allocate 32KB of memory. It'll round up to the nearest multiple 
>> of
>> a pointer size.
>>
>> On Wed, Sep 12, 2018 at 10:09 AM dan Med  wrote:
>>
>>> Oh one more thing, so each tab in chrome is handeled as a single
>>> process, but Is the same process sandboxes with the Windows 10 kernel.
>>> Security or there’s another process which is sandboxes and then the main
>>> tab process the ( renderer ) is executed inside of it ?
>>>
>>
>> That's a completely unrelated question which has nothing to do with
>> V8 and does not belong in this thread. I suggest to look around on
>> http://dev.chromium.org/developers for a bunch of things that have
>> been explained before.
>>
>> On Wed, 12 Sep 2018 at 00:12, Peter Schow  wrote:

> On Tue, Sep 11, 2018 at 2:09 PM dan Med 
> wrote:
> >
> > Would you suggest to build v8 such that I can debug it as I want
> ?
>
> It's difficult to go wrong with this approach if you want to better
> understand V8 or any large, complex system.
>
> --
> --
> v8-users mailing list
> v8-u...@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+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
 --
>>> --
>>> v8-users mailing list
>>> v8-u...@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+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> --
>> v8-users mailing list
>> v8-u...@googlegroups.com
>> 

Re: [v8-users] Need help with handlers in ObjectTemplate.

2018-09-11 Thread J Decker
I found it esaier to work with
SetAccessorProperty

https://v8docs.nodesource.com/node-0.12/db/df7/classv8_1_1_template.html#a25856e3bf1b8b0d3ee7865687a8e6d97

example
https://github.com/d3x0r/sack.vfs/blob/master/src/gui/sack_image_module.cc#L134
defines some get/set methods on an image class; that works with the
prototype template, but it's part of Template should also be availble on an
ObjectTemplate

the setter has a default of 0 (NULL)

but like imageTemplate->PrototypeTemplate()->SetAccessorProperty(
String::NewFromUtf8( isolate, "jpgQuality" )
, FunctionTemplate::New( isolate, ImageObject::getJpegQuality )
, FunctionTemplate::New( isolate, ImageObject::setJpegQuality ), DontDelete
);

But they just take 'regular' function definitions

void ImageObject::getJpegQuality( const FunctionCallbackInfo& args )
{ }
 void ImageObject::setJpegQuality( const FunctionCallbackInfo& args
) {}

Now, what happens if you also define a function of the same name I don't
know.


On Tue, Sep 11, 2018 at 6:24 AM Andrei Vinogradov 
wrote:

> Hello.
> I'm trying to create new template that should match required behaviour but
> now i'm stuck with NamedPropertyHandler.
> What I need to achieve:
> 1. All property access calls should be processed by unified handlers
> (getter/setter for indexed access and getter/setter for named access).
> (This part is working).
> 2. Template also should have a set of predefined functions with different
> handlers for each. (This part is not working).
>
> What I am doing. Assume that we have code like following:
>
> void NamedGetter(Local name, const PropertyCallbackInfo 
> ) { ... }
> void NamedSetter(Local name, Local value, const
> PropertyCallbackInfo ) { ... }
> void IndexedGetter(uint32_t index, const PropertyCallbackInfo 
> ) { ... }
> void IndexedSetter(uint32_t index, Local value, const
> PropertyCallbackInfo ) { ... }
> void FunctionAHandler(const FunctionCallbackInfo ) { ... }
>
> //Lets skip initialization code...
>
> Local funcName = String::NewFromUtf8(isolate, "FunctionA", v8::
> NewStringType::kNormal).ToLocalChecked();
>
> Local templ = ObjectTemplate::New(isolate);
> templ->Set(funcName, FunctionTemplate::New(isolate, FunctionAHandler,
> funcName));
> templ->SetHandler(NamedPropertyHandlerConfiguration(NamedGetter,
> NamedSetter));
> templ->SetHandler(IndexedPropertyHandlerConfiguration(IndexedGetter,
> IndexedSetter));
>
> //Creating instance of template in current context with name my_instance...
>
> Then, when i'm executing JS like "my_instance.FunctionA();" this is
> proccessed by V8 like i'm accessing property with name "FunctionA". I mean
> it's starting to execute NamedGetter function.
> And after that it fails with error:
>
> :10: Uncaught TypeError: my_instance.FunctionA is not a function
>
> If I'm not adding NamedPropertyHandler to template - FunctionAHandler is
> invoked like expected.
> So my question is - how to avoid executing NamedGetter when function with
> such name is defined on template? Or maybe i't possible to proccess
> function calls inside NamedGetter and avoid creating handlers for each
> function I need in template?
> I would appreciate any help with this.
>
> --
> --
> 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] Arraybuffer

2018-09-11 Thread J Decker
On Tue, Sep 11, 2018 at 12:44 AM dan Med  wrote:

> First of all, i'd like to say that for me the documentation is really.
> useless from a real technical point of view.
> So, what i'd like to understand is how v8 would compile a javascript
> "file" by that i mean how it would be
> represented in memory which methods will be called and so on
> (In the classes defined in the various v8 files, you don't get that sort
> of feeling about the memory allocator and such...
> i'd like to understand how to gather that knowledge.)
> Now, u said "kind of" for my question which was, when i allocate an
> arraybuffer in javascript will v8 call arraybufferbuilder ?
> But then one of my questions was how to invoke the append method?
> I know that if someone want's to expand an arraybuffer it will have to
> create another one and copy there those values...
> This is how i have a rough vision of the arraybuffer in memory:
>
> buffer > [   DATA ]
> "simple pointer" "size of the bytes which i can manipulate with a
> typedarray"
>

There's really nothing special about the memory gets the size of a
file, allocates a buffer and reads the file into it.
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L479

size_t len = sack_vfs_size( file );
uint8_t *buf = NewArray( uint8_t, len );
sack_vfs_read( file, (char*)buf, len );
Local arrayBuffer = ArrayBuffer::New( isolate, buf, len );

where buf is allocated from some allocator V8 doesn't even know about
the next few lines of code wrap it in a weak persistent holder that tracks
when the object gets deleted to be able to delete the 'buf' allocated...
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L447
(releaseBuffer)

You can find information about ArrayBuffer by searching for 'nodejs addon
arraybuffer'   Node is a handy platform for writing code that extends V8;
99% of the code you will write is actually interfacing to V8 and not Node.


> Il giorno mar 11 set 2018 alle ore 00:07 @soylentgraham <
> gra...@grahamreeves.com> ha scritto:
>
>> > When I talk about typedarray or anything else I referr to the
>> JavaScript side, so create an arraybuffer it will invoke that class in v8,
>> Kind of.
>>
>> > then build a view or not it depends how do I make v8 to call the append
>> method ?
>> I don't understand this question.
>> An array buffer in javascript is fixed in length. You cannot make it grow
>> or shrink on the javascript side.
>> To do anything, you need a view, so the code knows how to manipulate the
>> raw bytes in the array buffer.
>> See javascript documentation on array buffers;
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
>>
>> You personally shouldn't TRY to make it call the append method. If it
>> needs to grow, it'll grow. Why do you think you need to? Back to previous
>> messages, what are you trying to achieve??
>>
>> Gather your thoughts, and try and answer some of the questions I've asked
>> in previous emails; I asked them to help guide you so people can help with
>> your problem! (I'm still not exactly sure what you're trying to do)
>>
>>
>> On Monday, 10 September 2018 22:55:51 UTC+1, dan Med wrote:
>>>
>>> ATM I’m writing with my phone, here in EU is almost midnight so I will
>>> write u an email tomorrow fully detailed.
>>>
>>> Btw how do I call append ???
>>> I’m interested in how v8 works and manages JavaScript code that’s all.
>>>
>>> When I talk about typedarray or anything else I referr to the JavaScript
>>> side, so create an arraybuffer it will invoke that class in v8, then build
>>> a view or not it depends how do I make v8 to call the append method ?
>>>
>>> On Mon, 10 Sep 2018 at 23:46, @soylentgraham 
>>> wrote:
>>>
 > First, how big is the data member of the object ?

 As I said before. Capacity is the size of the memory allocated that
 data points at.


 > Is it as big as the actual array buffer length which I declare on
 JavaScript

 It will be either as big, or bigger. It can grow.
 bytes_used will be the size that matches javascript.


 > which I can build on top of it a typedarray ?

 This is a slightly different question, (and needs clarifying)
 When you create a typedarray in C++, it needs an array buffer.
 When you create a typedarray in javascript, it will have an array
 buffer behind it. (which you may or may not have created in javascript or
 c++, there are several ways of approaching this)


 > So, when a typedarray is build on top of an areaybuffer instance, how
 do I get to call the arraybufferbuilder::append ?

 Aha! a more specific question!
 Are you trying to call arraybufferbuilder::append in javascript, or c++?
 Why? are you trying to make a typedarray bigger? (in javascript or c++?)
 I believe once created they're a fixed size in javascript.
 I have a feeling on the c++ side, 

Re: [v8-users] Netwrok v8

2018-09-10 Thread J Decker
On Mon, Sep 10, 2018 at 6:05 AM  wrote:

> How does a signle process of the browser handle http and network traffic ?
>
Quite well.
What are you actually seeking?  It calls system libraries that provide
sockets just like any other app ...

> --
> --
> 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] Re: Calling method on Persistent

2018-09-06 Thread J Decker
On Thu, Sep 6, 2018 at 7:29 PM Mike Moening  wrote:

> Do I need an handle scope when I work on the Local?
>
Yes.

> Not sure what that would do for me.
>
> Thanks,
> Mike
>
> --
> --
> 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] Built

2018-08-13 Thread J Decker
there is Node which uses V8 and runs JS only
nodejs.org
chrome devtools will also connect to node to debug javascript.

On Mon, Aug 13, 2018 at 5:05 AM dan Med  wrote:

> how can i move forward it has beeen a month since  i tried to build this...
>
> 2018-08-13 14:04 GMT+02:00 dan Med :
>
>> it gave me this error again
>> and said go look at this link
>> https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md
>>
>> 2018-08-13 14:03 GMT+02:00 dan Med :
>>
>>> Anyone online
>>>
>>>
>>> 2018-08-13 12:52 GMT+02:00 dan Med :
>>>
 Now invio running again the fetch command, already did the depot tools
 part and gclient

 On Mon, 13 Aug 2018 at 00:13, dan Med  wrote:

> Yes but by compiling v8 I should be able to debug javascript pages
>
> On Sun, 12 Aug 2018 at 23:53, 'Jakob Kummerow' via v8-users <
> v8-users@googlegroups.com> wrote:
>
>> The official build instructions are at
>> https://github.com/v8/v8/wiki/Building-with-GN. They work.
>>
>> That said, V8 implements ECMAScript, and as such has no idea about
>> HTML or the DOM-related parts of JavaScript.
>>
>> On Sun, Aug 12, 2018 at 7:10 AM  wrote:
>>
>>> Hi i've been trying to build the javascript v8 engine for as long as
>>> 3 weeks now,. i've followed many guides all of them miss some
>>> information
>>> I'm looking for a guide that helps to build the engine it self along
>>> all of its compiler and stuff such that i could be able to throw at it a
>>> /HTML/JS page.
>>> Thank you
>>>
>>> --
>>> --
>>> 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.


[v8-users] Infinite stack using setTimeout() (the way I am)

2018-07-05 Thread J Decker

I've been doing

function Tick() {
/*do something*/
   setTimeout( tick, 1000 );
}

but I notice in dev tools when I break in that, there seems to be an 
infinite growing nest of contexts(?) ...

How can I prevent that?
THe previous values in the previous calls can't be referenced by 
anything  Or is the /* do something */ somehow significant?

-- 
-- 
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] Re: What is an event?

2018-06-16 Thread J Decker


On Saturday, June 16, 2018 at 7:41:49 AM UTC-7, sn...@olymega.org wrote:
>
> I am looking for what an event is in terms of its implementation.I know 
> what an event is in the abstract sense:
>
> https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events
>
> For instance, everyone knows what a 'list' is - a term that applies 
> equally to 'shopping list' as well as 'collection of data'. However, I'm 
> more interested in event *implementation*, e.g. how a programming 
> language implements lists as *arrays *and* Objects*. I would like to know 
> how events exist concurrently as code in the browser (written in in C++) 
> and as data. (picked by an event handler). 
>
> Thank you! The official docs are sparse on how events are implemented. So 
> far, I know that they are 'objects' though it's not clear whether these are 
> objects v.v. C++ or JavaScript. 
>

any of the above.
Events are a map of some sort of identifier and a callback.
For my websocket interface, which is C/C++ the events are tracked in C/C++ 
structures. 
For a graph database I was tinkering with in ES6, the events are tracked in 
just javascript ojects.

A super simple way (and I'm sure there's lots of ways of doing this)

var myObjectWithEvents = { events : {},
   on( event, callbackOrData ) {
   if( typeof callbackOrData === "function" ) {
this.events[event] = callbackOrData;   // register event handler
   } else {
if( event in this.events ) {
this.events[event]( callbackOrData );  // invoke event 
handler
}
   }
}
};

myObjectWithEvents.on( "click", (data)=>{ console.log( "got click event..." 
) } );   /// register an event handler to 'click'

myObjectWithEvents.on( "click", { x:1, y : 250 } );   // trigger an event...


Instead of assigning directly, each event in 'events' could be an array ... 
[]  and .push( callbackOrData ); would allow you to assign multiple 
handlers to each eent instead of a single... and then you'd just  do 
something likethis.events[event].forEach( cb=> cb( callbackOrData ) ) 
instead.

The above was something I got from Gun DB; if the argument passed to 'on' 
is a function, keep that function as a callback stored as the name of the 
event specified.  If it's not a function, call any previously registered 
event with the data passed to 'on', which then overloads 'on' as both the 
uhh addEventListener()  and the emit().


-- 
-- 
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] Does anyone know what an external arraybuffer is and how to create it.

2018-04-23 Thread J Decker
On Mon, Apr 23, 2018 at 5:55 AM, cyril <hit.liushenr...@gmail.com> wrote:

> Sorry for my unclear expression, I mean the External ArrayBuffer in chrome.
>

This group is about V8... not chrome;

new ArrayBuffer( size ) ?



>
> 在 2018年4月23日星期一 UTC+8下午6:22:15,J Decker写道:
>>
>> https://gist.github.com/luismreis/4160350
>>
>> '?? NativeArrays'  section
>>
>> Or like here https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_m
>> odule.cc#L464
>> that assigns a 'holder' that is called when SetWeak callback is called to
>> release the buffer when garbage collected...
>>
>>
>>
>> On Mon, Apr 23, 2018 at 2:48 AM, cyril <hit.liu...@gmail.com> wrote:
>>
>>> Hi,all
>>>
>>> I encountered some problems while learning v8. I am very confused about
>>> the external arraybuffer in v8. So, does anyone know what an external
>>> arraybuffer is and how to create it?
>>> thank you!
>>>
>>> --
>>> --
>>> v8-users mailing list
>>> v8-u...@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+u...@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] Does anyone know what an external arraybuffer is and how to create it.

2018-04-23 Thread J Decker
https://gist.github.com/luismreis/4160350

'?? NativeArrays'  section

Or like here
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L464
that assigns a 'holder' that is called when SetWeak callback is called to
release the buffer when garbage collected...



On Mon, Apr 23, 2018 at 2:48 AM, cyril  wrote:

> Hi,all
>
> I encountered some problems while learning v8. I am very confused about
> the external arraybuffer in v8. So, does anyone know what an external
> arraybuffer is and how to create it?
> thank you!
>
> --
> --
> 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] Re: Slower Performance than expected

2018-04-06 Thread J Decker
Was forumating a crbug; and realized I was using Node.  I'm doing the
console.log with node
when I grab the code and run it in a webpage it doesn't suffer the same
slowdown.

On Fri, Apr 6, 2018 at 3:13 PM, J Decker <d3c...@gmail.com> wrote:

> Sorry got busy with other things.
>
> This gist is fast.
> https://gist.github.com/d3x0r/be849400be3ea30877568e5656a86ca3
> how to slow down.
>
> (line 1)
> function pcg_setseq_128_srandom_r()
> {
>  //const state = new Uint32Array([0,0,0,0,0,0,0,0]);
>  const state = [0,0,0,0,0,0,0,0];
>
> uncomment the first line to use uInt32array and comment the second const
> state line .  (use typed array instead of array).
>
> (On my system it reports Done in  2045 /ms 48899.75550122249
> 1564792.1760391197) as is , with a standard array.
> If it runs more than 4 seconds I end it... because it will be 15-20
> seconds .  (Done in  22615 /ms 4421.843908910016 141499.0050851205)
>
> With the following mentioned speedups Uint32array IS faster
> The first thing, replace the state with Uint32array, if fast reports (Done
> in  1530 /ms 65359.47712418301 2091503.2679738563 )
>
> --
> Okay?  Is that reproducable?
>
>
>
> How to speed up.
> 1) remove the console.log( testRng ); on line 46.  (it's done before the
> loop, no the logging itself is not measured in the speed)
> or 2) comment out state: new Uint32Array([0,0,0,0,0,0,0,0]),  on line
> 10.  This is a Uint32Array that is put into the RNG object returned;  and
> if console.log doesn't log a uint32array type it's fast.
> 3)
>
>
>
> On Friday, April 6, 2018 at 2:28:40 AM UTC-7, Jakob Gruber wrote:
>>
>> If you do end up with a good repro for the performance difference between
>> typed arrays and arrays, please post it at crbug.com/v8/new.
>>
>> On Fri, Apr 6, 2018 at 8:33 AM, <mog...@syntheticsemantics.com> wrote:
>>
>>> Are you able to hoist the memory allocations out of the library so the
>>> caller can allocate the buffers it needs and reuse them from call to call?
>>> new in JS has GC overhead not present in C++ alloc/free.  Aside from
>>> those variables, the rest are stack allocations and GC won't play much role.
>>>
>>>  -J
>>>
>>>
>>> On Wednesday, April 4, 2018 at 7:03:05 PM UTC-7, J Decker wrote:
>>>>
>>>> How long of a story to tell(?)...
>>>>
>>>> I have this procedural random generator, that uses the result of sha2
>>>> as a stream of bits, regenerating another sha2 hash when the 256 bits are
>>>> all consumed.  I started to use this for perlin noise generation, and
>>>> thought I found sha2 was the culprit consuming most of the time.  Since I'm
>>>> making something just generally random, I went looking for alternative,
>>>> lightweight, RNGs. After digging for a while I stumbled on PCG (
>>>> http://www.pcg-random.org/using-pcg.html) It's basically a header-only
>>>> library because it attempts to generate everything as inline...
>>>>
>>>> I made this JS port of it  https://gist.github.com/d3
>>>> x0r/345b256be6569c0086c328a8d1b4be01
>>>> This is the first revision ... https://gist.github.com/d3
>>>> x0r/345b256be6569c0086c328a8d1b4be01/fffa8e906d5723e66f7e9ba
>>>> a950b3b3d5b4895c7
>>>> It has a better flow matching what the C code does closer... the
>>>> current version is fast generating 115k bits per millisecond (vs the 9.3k
>>>> bpms of sha2); however, when compared to the C version, which generates
>>>> 1.1Mbps it's a factor of 10 off... and the routine is generally only doing
>>>> 64 bit integer math (though the test was compiled in 32 bit mode so it was
>>>> really just 32 bit registers emulating 64 bit).
>>>>
>>>> if I just change the arrays created in getState() (first function), to
>>>> Uint32Array() it runs MUCH slower...
>>>>
>>>> 
>>>> As I write this I was updating some, and some of my numbers from before
>>>> are a factor of 8 off because I was counting bytes not bits; except in the
>>>> sha2, which is really slow... But I would like to take this opportunity to
>>>> say...
>>>>
>>>> crypto.subtle.digest("SHA-256", buffer).then(hash=>hash );
>>>>
>>>> is the same output type as my javascript version I'm using ( forked
>>>> from a fork of forge library and consolidated to just the one return
>>>> type...), but is another 10x slower than my javas

Re: [v8-users] Re: Slower Performance than expected

2018-04-06 Thread J Decker
Sorry got busy with other things.

This gist is fast.
https://gist.github.com/d3x0r/be849400be3ea30877568e5656a86ca3
how to slow down.  

(line 1)
function pcg_setseq_128_srandom_r()
{
 //const state = new Uint32Array([0,0,0,0,0,0,0,0]);
 const state = [0,0,0,0,0,0,0,0];

uncomment the first line to use uInt32array and comment the second const 
state line .  (use typed array instead of array).  

(On my system it reports Done in  2045 /ms 48899.75550122249 
1564792.1760391197) as is , with a standard array.
If it runs more than 4 seconds I end it... because it will be 15-20 seconds 
.  (Done in  22615 /ms 4421.843908910016 141499.0050851205)

With the following mentioned speedups Uint32array IS faster 
The first thing, replace the state with Uint32array, if fast reports (Done 
in  1530 /ms 65359.47712418301 2091503.2679738563 )

--
Okay?  Is that reproducable?



How to speed up.
1) remove the console.log( testRng ); on line 46.  (it's done before the 
loop, no the logging itself is not measured in the speed)
or 2) comment out state: new Uint32Array([0,0,0,0,0,0,0,0]),  on line 10.  
This is a Uint32Array that is put into the RNG object returned;  and if 
console.log doesn't log a uint32array type it's fast.
3) 



On Friday, April 6, 2018 at 2:28:40 AM UTC-7, Jakob Gruber wrote:
>
> If you do end up with a good repro for the performance difference between 
> typed arrays and arrays, please post it at crbug.com/v8/new. 
>
> On Fri, Apr 6, 2018 at 8:33 AM, <mog...@syntheticsemantics.com 
> > wrote:
>
>> Are you able to hoist the memory allocations out of the library so the 
>> caller can allocate the buffers it needs and reuse them from call to call?  
>> new in JS has GC overhead not present in C++ alloc/free.  Aside from 
>> those variables, the rest are stack allocations and GC won't play much role.
>>
>>  -J
>>
>>
>> On Wednesday, April 4, 2018 at 7:03:05 PM UTC-7, J Decker wrote:
>>>
>>> How long of a story to tell(?)...
>>>
>>> I have this procedural random generator, that uses the result of sha2 as 
>>> a stream of bits, regenerating another sha2 hash when the 256 bits are all 
>>> consumed.  I started to use this for perlin noise generation, and thought I 
>>> found sha2 was the culprit consuming most of the time.  Since I'm making 
>>> something just generally random, I went looking for alternative, 
>>> lightweight, RNGs. After digging for a while I stumbled on PCG (
>>> http://www.pcg-random.org/using-pcg.html) It's basically a header-only 
>>> library because it attempts to generate everything as inline... 
>>>
>>> I made this JS port of it  
>>> https://gist.github.com/d3x0r/345b256be6569c0086c328a8d1b4be01  
>>> This is the first revision ... 
>>> https://gist.github.com/d3x0r/345b256be6569c0086c328a8d1b4be01/fffa8e906d5723e66f7e9baa950b3b3d5b4895c7
>>>   
>>> It has a better flow matching what the C code does closer... the current 
>>> version is fast generating 115k bits per millisecond (vs the 9.3k bpms of 
>>> sha2); however, when compared to the C version, which generates 1.1Mbps 
>>> it's a factor of 10 off... and the routine is generally only doing 64 bit 
>>> integer math (though the test was compiled in 32 bit mode so it was really 
>>> just 32 bit registers emulating 64 bit).
>>>
>>> if I just change the arrays created in getState() (first function), to 
>>> Uint32Array() it runs MUCH slower... 
>>>
>>> 
>>> As I write this I was updating some, and some of my numbers from before 
>>> are a factor of 8 off because I was counting bytes not bits; except in the 
>>> sha2, which is really slow... But I would like to take this opportunity to 
>>> say...
>>>
>>> crypto.subtle.digest("SHA-256", buffer).then(hash=>hash );
>>>
>>> is the same output type as my javascript version I'm using ( forked from 
>>> a fork of forge library and consolidated to just the one return type...), 
>>> but is another 10x slower than my javascript sha-256.
>>>
>>> I keep thinking 'Oh I'll just compile this and even use intel 
>>> accelearted sha2msg1 and sha2msg2 instructions to make the C version 8x 
>>> faster than it is in C straight, which itself was already faster than the 
>>> JS version; and hook it into a ... ( oh wait I want to do this on a 
>>> webpage! can't say Node addon there...).  
>>>
>>> Well... back to optimizing.
>>> 
>>>
>>> I was working also on a simple test case to show where using a simple 
>>> a

[v8-users] Slower Performance than expected

2018-04-04 Thread J Decker
How long of a story to tell(?)...

I have this procedural random generator, that uses the result of sha2 as a 
stream of bits, regenerating another sha2 hash when the 256 bits are all 
consumed.  I started to use this for perlin noise generation, and thought I 
found sha2 was the culprit consuming most of the time.  Since I'm making 
something just generally random, I went looking for alternative, 
lightweight, RNGs. After digging for a while I stumbled on PCG 
(http://www.pcg-random.org/using-pcg.html) It's basically a header-only 
library because it attempts to generate everything as inline... 

I made this JS port of 
it  https://gist.github.com/d3x0r/345b256be6569c0086c328a8d1b4be01  
This is the first revision 
... 
https://gist.github.com/d3x0r/345b256be6569c0086c328a8d1b4be01/fffa8e906d5723e66f7e9baa950b3b3d5b4895c7
  
It has a better flow matching what the C code does closer... the current 
version is fast generating 115k bits per millisecond (vs the 9.3k bpms of 
sha2); however, when compared to the C version, which generates 1.1Mbps 
it's a factor of 10 off... and the routine is generally only doing 64 bit 
integer math (though the test was compiled in 32 bit mode so it was really 
just 32 bit registers emulating 64 bit).

if I just change the arrays created in getState() (first function), to 
Uint32Array() it runs MUCH slower... 


As I write this I was updating some, and some of my numbers from before are 
a factor of 8 off because I was counting bytes not bits; except in the 
sha2, which is really slow... But I would like to take this opportunity to 
say...

crypto.subtle.digest("SHA-256", buffer).then(hash=>hash );

is the same output type as my javascript version I'm using ( forked from a 
fork of forge library and consolidated to just the one return type...), but 
is another 10x slower than my javascript sha-256.

I keep thinking 'Oh I'll just compile this and even use intel accelearted 
sha2msg1 and sha2msg2 instructions to make the C version 8x faster than it 
is in C straight, which itself was already faster than the JS version; and 
hook it into a ... ( oh wait I want to do this on a webpage! can't say Node 
addon there...).  

Well... back to optimizing.


I was working also on a simple test case to show where using a simple array 
vs a typed array causes a speed difference, but it's not immediately 
obvious what I'm doing that's causing it to deoptimize so I'll work on 
building that up until it breaks; or conversely strip the other until it 
speeds up..

https://github.com/d3x0r/-/blob/master/org.d3x0r.common/salty_random_generator.js#L86
  
This is getting the bits from a typed array; and it's really not that 
complex (especially if only getting 1 bit at a time which is what I was 
last speed testing with; but turns out all the time is really here, 
swapping out sha2 for pcg(without typed arrays) dropped that from 150ms to 
50ms but the remaining was still 3500ms... so I misread the initial 
performance graph I guess... 

There's a stack of what were C macros to make the whole thing more 
readable... 
https://github.com/d3x0r/-/blob/master/org.d3x0r.common/salty_random_generator.js#L25
 
and if I inline these, there's no improvement so I guess they're all small 
to qualify for auto inlining anyway.  The version that's current on github 
ended up creating a new uint32array(1) for every result; I moved that out 
locally so I can use just a single buffer for that result and it sped up 
the initialization from 700ms to 200ms (cumulative times) but there's still 
like 80% of the time in the remainder of the getBuffer routine; maybe I 
need to move things out of the uint8arrays (data from sha2/pcg)


-- 
-- 
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] Embedded V8 and Profiler

2018-03-21 Thread J Decker
I think it depends highly on what you're doing in the code being profiled.
I was recently playing with perlin noise and A* path finding... I had
initially implemented it as a tight loop and even with a output to a canvas
context, profiling data wouldn't load.  I broke it up so I have a
setTimeout(0)  inbetween iterations and now profiles load with no problem.

On Wed, Mar 21, 2018 at 5:03 PM, ibon  wrote:

> I have an android app with v8 arm7 embedded. It runs on android 7.0, with
> v8 6.3.292
>
> I use chrome for remote dev tools debugging.
>
> With current Chrome 66 on OSX 10.13.3, the new dev tools Performance tab
> gets stuck 'Loading profile' after any profiling session.
> The Previous Javascript Profiler (more tools -> javascript profiler) works
> worse since it hangs my app until i close dev tools session.
> Debugger and memory work as expected though.
>
> It used to work perfectly in previous chrome versions.
>
> Is there anything I could do to make it work, or is it a known bug ?
>
> Any help would be very much appreciated.
> Thanks.
>
> --
> --
> 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] Re: Crash setting accessor property

2018-02-20 Thread J Decker
(Oops hit enter too soon)

  node: '9.2.0',
  v8: '6.2.414.44-node.11',

Local c = Object::New( isolate );
c->SetAccessorProperty( String::NewFromUtf8( isolate, "password" )
, Local()
, Function::New( isolate, ControlObject::setEditFieldPassword )
, DontDelete );

This is an attempt to make a set-only property... SetAccessorProperty
crashes on access of a NULL pointer.



On Tue, Feb 20, 2018 at 3:46 AM, J Decker <d3c...@gmail.com> wrote:

>
>

-- 
-- 
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] Crash setting accessor property

2018-02-20 Thread J Decker


-- 
-- 
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] Can "threading" be implemented by mapping v8 heap to shared memory in linux?

2018-01-09 Thread J Decker
On Tue, Jan 9, 2018 at 8:30 AM,  wrote:

> There is active work on parallel JS with a range of approaches to shared
> memory parallelism.  I maintain a list of parallel JS projects
>  and
> am interested in finding applications that use them.  Are you working with
> a particular application that lead to a requirement for shared-memory
> parallel JS?
>
>
A voxel based 3d engine.  Offloading rebuilding meshes to other threads is
of great benefit; allowing much more complex (smoothed) meshing.  The
meshes, once available, should be immediately available to use in the
render thread.  A single sector 32x32x32 can be a meg as a mesh; the
visible area is 125 sectors.
Also physics for things moving across the voxels; which updates back for
the few hundred entities' positions and orientations could be message
based... not requiring shared memory.
https://github.com/d3x0r/voxelarium.js  (still very much a work in progress
and non-stable; and is only a hobby-time project)


>   -J
>
>
> On Monday, January 8, 2018 at 7:30:33 AM UTC-8, Bogdan wrote:
>>
>> I understand that updating object in shared memory need synchronization
>> and even with in-memory database task in general there will be a global
>> lock (not per-object because transaction will spread by different tables
>> and object) and only one process will write to memory so I think just
>> global lock will be enough for most tasks. But reading from shared memory
>> is safe and there is no reason to not use all cpu cores to achieve more
>> performance and that's why go and other languages will overcome js in this
>> tasks. But I hope js will be able to compete and new features like
>> SharedArrayBuffer and atomics seems like moving forward javascript to the
>> right direction and I don't see why "JavaScript is not designed for such
>> purposes.". Does SharedArrayBuffer supposed to do zero copy reading in
>> different workers? How it implemented - by multiple threads or maybe it
>> already using shared memory and different process?
>>
>> On Mon, Jan 8, 2018 at 6:04 PM, Jakob Kummerow 
>> wrote:
>>
>>> No, you cannot simply share all memory to get multi-threading. For
>>> safely/correctly working with shared memory, you need
>>> locking/synchronization primitives as well as certain guarantees in the
>>> language's memory model. JavaScript is not designed for such purposes.
>>>
>>>
>>> On Mon, Jan 8, 2018 at 3:52 PM Bogdan  wrote:
>>>
 I don't know all details, I just a regular node developer who came up
 with idea of "threading" in js and hope anybody with deep knowledge will
 clarify some things. Javascript have old problem of lacking threading and
 all advices of using multiple processes doesn't help because there are
 important tasks  (for example in-memory database or managing application
 cache) which needs shared memory to utilize all cpu cores and having full
 copy of that memory and synchronizing it by coping data over channels
 doesn't make sense. Recently I've found out an interesting linux feature
 like shader memory with shm_open and mmap which can allow zero-copy and
 zero-overhead access to shared memory from different processes. There are
 also some node modules which exposes this feature to javascript but seems
 like all they can do is exposing  shared memory to javascript as an array
 which means all object managing, garbage collector, and other useful
 features we need to do all by ourselves. So I am wondering can v8 (if
 cannot now, maybe in it will with little hacking) allow to just map all
 heap into shared buffer so we can use the same objects from another process
 without copying?

 --
 --
 v8-users mailing list
 v8-u...@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+u...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>> --
>>> --
>>> v8-users mailing list
>>> v8-u...@googlegroups.com
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "v8-users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/v8-users/2Z2UFFQrziE/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> v8-users+u...@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" 

Re: [v8-users] Can "threading" be implemented by mapping v8 heap to shared memory in linux?

2018-01-08 Thread J Decker
nwjs claims to support web worker with node, allowing true threading.  Each
thread gets its own javascript context and they don't share anything.  They
only communicate with messages.  The workers are entirely separate from
each other.

https://github.com/nwjs/nw.js/issues/494
https://groups.google.com/forum/#!msg/nwjs-general/jljGxjIyxK4/pVqyidTrBAAJ

pretty sure you'll need an addon if you want to share large chunks of data
using typed arrays... and/or provide other synchronization around the
buffers.


On Mon, Jan 8, 2018 at 7:30 AM, Bogdan Orlov  wrote:

> I understand that updating object in shared memory need synchronization
> and even with in-memory database task in general there will be a global
> lock (not per-object because transaction will spread by different tables
> and object) and only one process will write to memory so I think just
> global lock will be enough for most tasks. But reading from shared memory
> is safe and there is no reason to not use all cpu cores to achieve more
> performance and that's why go and other languages will overcome js in this
> tasks. But I hope js will be able to compete and new features like
> SharedArrayBuffer and atomics seems like moving forward javascript to the
> right direction and I don't see why "JavaScript is not designed for such
> purposes.". Does SharedArrayBuffer supposed to do zero copy reading in
> different workers? How it implemented - by multiple threads or maybe it
> already using shared memory and different process?
>
> On Mon, Jan 8, 2018 at 6:04 PM, Jakob Kummerow 
> wrote:
>
>> No, you cannot simply share all memory to get multi-threading. For
>> safely/correctly working with shared memory, you need
>> locking/synchronization primitives as well as certain guarantees in the
>> language's memory model. JavaScript is not designed for such purposes.
>>
>
>>
>> On Mon, Jan 8, 2018 at 3:52 PM Bogdan  wrote:
>>
>>> I don't know all details, I just a regular node developer who came up
>>> with idea of "threading" in js and hope anybody with deep knowledge will
>>> clarify some things. Javascript have old problem of lacking threading and
>>> all advices of using multiple processes doesn't help because there are
>>> important tasks  (for example in-memory database or managing application
>>> cache) which needs shared memory to utilize all cpu cores and having full
>>> copy of that memory and synchronizing it by coping data over channels
>>> doesn't make sense. Recently I've found out an interesting linux feature
>>> like shader memory with shm_open and mmap which can allow zero-copy and
>>> zero-overhead access to shared memory from different processes. There are
>>> also some node modules which exposes this feature to javascript but seems
>>> like all they can do is exposing  shared memory to javascript as an array
>>> which means all object managing, garbage collector, and other useful
>>> features we need to do all by ourselves. So I am wondering can v8 (if
>>> cannot now, maybe in it will with little hacking) allow to just map all
>>> heap into shared buffer so we can use the same objects from another process
>>> without copying?
>>>
>>> --
>>> --
>>> 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 a topic in the
>> Google Groups "v8-users" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/v8-users/2Z2UFFQrziE/unsubscribe.
>> To unsubscribe from this group and all its topics, 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] Convert Value* back to Local

2017-12-18 Thread J Decker
On Mon, Dec 18, 2017 at 2:43 PM, Ben Noordhuis <i...@bnoordhuis.nl> wrote:

> On Fri, Dec 15, 2017 at 7:17 AM, J Decker <d3c...@gmail.com> wrote:
> > most usages the callbacks will all be performed before returning back to
> the
> > orignal javascript caller, but, it can be that the javascript is adding
> > streaming data to the text processor iteritively so there may be a long
> time
> > between one call to f() and the next... would the 'result' be subject to
> > garbage collection when it's not in a Local<> or Persistent<>  ?
>
> Yes, and keep in mind a Local won't safe you if its HandleScope is
> destroyed in the interim - it needs to be a Persistent in that case.
>
to clarify; you're saying it will be potentially garbage collected unless
in a persistent?

and with the result.Clear(); it's no longer in the local so that
destruction wouldn't matter.


> --
> --
> 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] Bug in v8/src/parsing/scanner?

2017-12-16 Thread J Decker
On Sat, Dec 16, 2017 at 4:35 PM, 'Mathias Bynens' via v8-users <
v8-users@googlegroups.com> wrote:

>
> On Fri, Dec 15, 2017 at 4:44 PM, J Decker <d3c...@gmail.com> wrote:
>
>> The code below comes from ScanString()
>> I noticed that if the scanner encounters a '\' before a c0 > kMaxAscii
>> HandleLeadSurrogate() (0xd800+0xdc00 surrogate handling) is no longer done.
>>
>> I tried to make a test file that had such things, but node failed to read
>> utf-16 encoded file even with BOM marks...
>>
>
> I’m not sure what you mean exactly, but it sounds like you could use
> `eval()` to test this more directly.
>
>
>> But also, if there is no backslash, then PS and LS (0x2028, 0x2029)
>> characters are not considered valid line ending and would be stored in the
>> string literal (IsLineTerminator test)
>>
>
> This doesn’t seem to be the case:
>
> $ rlwrap v8
> V8 version 6.5.20
> d8> eval('"a\u2028b"')
> undefined:1: SyntaxError: Invalid or unexpected token
> "a
> ^^
> SyntaxError: Invalid or unexpected token
> at (d8):1:1
>

I see; that ends up being > kMaxAscii which I missed; and the other case
Advance() ends up doing the handle lead surrage internally. Got it; thanx.


>
>> --
>> --
>> 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] Bug in v8/src/parsing/scanner?

2017-12-15 Thread J Decker
The code below comes from ScanString()
I noticed that if the scanner encounters a '\' before a c0 > kMaxAscii
HandleLeadSurrogate() (0xd800+0xdc00 surrogate handling) is no longer done.

I tried to make a test file that had such things, but node failed to read
utf-16 encoded file even with BOM marks

But also, if there is no backslash, then PS and LS (0x2028, 0x2029)
characters are not considered valid line ending and would be stored in the
string literal (IsLineTerminator test)

  while (true) {
if (c0_ > kMaxAscii) {
  HandleLeadSurrogate();
  break;
}
if (c0_ == kEndOfInput || c0_ == '\n' || c0_ == '\r') return
Token::ILLEGAL;
if (c0_ == quote) {
  literal.Complete();
  Advance();
  return Token::STRING;
}
char c = static_cast(c0_);
if (c == '\\') break;
Advance();
AddLiteralChar(c);
  }

  while (c0_ != quote && c0_ != kEndOfInput && !IsLineTerminator(c0_)) {
uc32 c = c0_;
Advance();
if (c == '\\') {
  if (c0_ == kEndOfInput || !ScanEscape()) {
return Token::ILLEGAL;
  }
} else {
  AddLiteralChar(c);
}
  }

-- 
-- 
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] Re: Convert Value* back to Local

2017-12-14 Thread J Decker
On Thu, Dec 14, 2017 at 10:17 PM, J Decker <d3c...@gmail.com> wrote:

>
> I have this process that wants to take the result of a callback and then
> pass that as the object for the next callback invokation...
>
> (truncated; argc is missing for instance; mostly I'm just intested in
> result, and the arg back in )
>
> void f( uintptr_t psv )
> {
> Local *argv = new Local[argc+1];
>
> Local recv = ((Value*)psv)->ToObject();
>
> Local cb = rule->handler.Get( config->isolate );
> Local result = cb->Call( recv, argc, argv );
> // figured I can get the result this way, and keep it ?
> uintptr_t objResult = (uintptr_t)*result;
> result.Clear();
> return objResult; // this gets passed to next f(psv)
> }
>
>
> on the javascript side the callback might be something like
>
> config.add( "format %d", function( arg ) {
>this.format_arg = arg;
>return this;
> }
>
> so any time the string "format ###" is found, the callback is triggered
> with ### formatted as an integer argument (for instance )
>
>
> most usages the callbacks will all be performed before returning back to
> the orignal javascript caller, but, it can be that the javascript is adding
> streaming data to the text processor iteritively so there may be a long
> time between one call to f() and the next... would the 'result' be subject
> to garbage collection when it's not in a Local<> or Persistent<>  ?
>

I would have a very last handler

static uintptr_t CPROC releaseArg( uintptr_t lastArg ) {
Local deleteMe = ( (Value*)lastArg )->ToObject();
return 0;
}

which should release it when the stream is done so it shouldn't leak if
it's not collected...

-- 
-- 
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] Convert Value* back to Local

2017-12-14 Thread J Decker
I have this process that wants to take the result of a callback and then
pass that as the object for the next callback invokation...

(truncated; argc is missing for instance; mostly I'm just intested in
result, and the arg back in )

void f( uintptr_t psv )
{
Local *argv = new Local[argc+1];

Local recv = ((Value*)psv)->ToObject();

Local cb = rule->handler.Get( config->isolate );
Local result = cb->Call( recv, argc, argv );
// figured I can get the result this way, and keep it ?
uintptr_t objResult = (uintptr_t)*result;
result.Clear();
return objResult; // this gets passed to next f(psv)
}


on the javascript side the callback might be something like

config.add( "format %d", function( arg ) {
   this.format_arg = arg;
   return this;
}

so any time the string "format ###" is found, the callback is triggered
with ### formatted as an integer argument (for instance )


most usages the callbacks will all be performed before returning back to
the orignal javascript caller, but, it can be that the javascript is adding
streaming data to the text processor iteritively so there may be a long
time between one call to f() and the next... would the 'result' be subject
to garbage collection when it's not in a Local<> or Persistent<>  ?

-- 
-- 
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] BSON to v8::Object performance issue

2017-11-17 Thread J Decker
On Fri, Nov 17, 2017 at 7:25 AM, Jean-Marc Le Roux <jeanmarc.ler...@aerys.in
> wrote:

> My assumption is that my test app terminates before the GC has a chance to
> run.
> To test this:
>
>- I run node with the --expose-gc option
>- I call global.gc() at the end of my test app
>
> In this case, the destructor of my ObjectWrap is indeed called.
>
> *So it seams the GC doesn't simply "collect everything" when the app
> terminates.*
> *Why is that?*
>
> It sounds like a pretty bad things to do: some behaviors might expect the
> destructor to be called in order to close a socket, etc...
>

because all memory is released. when the app exits.  Why do extra work of
minor side effects?
but ya, if tf you were returning like a file to a handle and expected the
close in order to flush all data out to a device it's bad...

You can attach to Node::AtExit( ... )
https://nodejs.org/api/addons.html#addons_atexit_hooks

which should be called so you an finalize such things.

but sockets get closed by the system when a application exits also.  and
files are closed



>
> On Friday, November 17, 2017 at 10:27:22 AM UTC+1, Jean-Marc Le Roux wrote:
>>
>> Thanks for the great help!
>> I think it makes a lot of sense now.
>>
>> So I've extended ObjectWrap like so:
>>
>> class BSONObject : public node::ObjectWrap
>>> {
>>> private:
>>> bson_t* _bson;
>>> public:
>>> BSONObject(bson_t* bson, Local tpl) :
>>> _bson(bson)
>>> {
>>> Local obj = tpl->NewInstance();
>>> initialize(v8::Isolate::GetCurrent(), obj, bson);
>>> Wrap(obj);
>>> }
>>
>>
>>
>>  ~BSONObject()
>>> {
>>> std::cout << "~BSONObject()" << std::endl;
>>> bson_destroy(_bson);
>>> }
>>
>>
>>
>> static
>>> Local
>>> create_template(Isolate* isolate, const bson_t* document)
>>> {
>>> Local tpl = ObjectTemplate::New(isolate);
>>> tpl->SetInternalFieldCount(1);
>>
>>
>> And the "insert" function that I expose in JS and that instanciates the
>> BSONObject is written like this:
>>
>> void
>>> insert(const FunctionCallbackInfo& args)
>>> {
>>> Isolate* isolate = args.GetIsolate();
>>>
>>> db->insert(
>>> json_stringify(isolate, args[0]),
>>> [, isolate](const bson_t* document)
>>> {
>>> if (!args[1]->IsUndefined())
>>> {
>>>     Local callback = Local::Cast(args[1])
>>> ;
>>> Local obj = Object::New(isolate);
>>> *Local argv[] = { (new
>>> BSONObject(bson_copy(document)))->handle(isolate) };*
>>> callback->Call(isolate->GetCurrentContext()->Global(),
>>> 1, argv);
>>> }
>>> }
>>> );
>>> }
>>
>>
>> It runs fine.
>> But the destructor is never called (I never see "~BSONObject()" on
>> stdout).
>>
>> Did I miss something?
>>
>> Thanks !
>>
>> 2017-11-16 22:01 GMT+01:00 J Decker <d3c...@gmail.com>:
>>
>>> You don't manage the instance, the v8 engine does.  When it's no longer
>>> referenced in the engine, it's garbage collected which triggers the
>>> callback set when the perisstent object is made weak.
>>>
>>> You don't need to keep it anywhere, the object returned into the engine
>>> has Internal Fields ( SetInternalFieldCount(1) ) which is used to point to
>>> your native class instance.   So when the callback is called, it knows what
>>> to call to destruct it.
>>>
>>> You have to 'keep it' in the javascript scrpit if you want to keep it,
>>> it's not 'kept' in the native code...
>>>
>>>
>>> --- This is some code I've done that uses setweak directly; but it's
>>> fairly scattered
>>>
>>> https://github.com/d3x0r/sack.vfs/blob/master/src/jsonParse.cc#L18
>>>
>>> You can create an instance of your wrapped object with
>>>
>>> Local cons = Local::New( isolate, constructor );
>>> cons->NewInstance( isolate->GetCurrentContext(), argc, argv
>>> ).ToLocalChecked() ;
>>>
>>> Hmm that's not the best example source...
>>>
>>> https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_mo

Re: [v8-users] BSON to v8::Object performance issue

2017-11-16 Thread J Decker
You don't manage the instance, the v8 engine does.  When it's no longer
referenced in the engine, it's garbage collected which triggers the
callback set when the perisstent object is made weak.

You don't need to keep it anywhere, the object returned into the engine has
Internal Fields ( SetInternalFieldCount(1) ) which is used to point to your
native class instance.   So when the callback is called, it knows what to
call to destruct it.

You have to 'keep it' in the javascript scrpit if you want to keep it, it's
not 'kept' in the native code...


--- This is some code I've done that uses setweak directly; but it's fairly
scattered

https://github.com/d3x0r/sack.vfs/blob/master/src/jsonParse.cc#L18

You can create an instance of your wrapped object with

Local cons = Local::New( isolate, constructor );
cons->NewInstance( isolate->GetCurrentContext(), argc, argv
).ToLocalChecked() ;

Hmm that's not the best example source...

https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L407

This creates a buffer, and makes it weak...
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L438

Local arrayBuffer = ArrayBuffer::New( isolate, buf, len );
PARRAY_BUFFER_HOLDER holder = GetHolder();
holder->o.Reset( isolate, arrayBuffer );
holder->o.SetWeak( holder, releaseBuffer,
WeakCallbackType::kParameter );
holder->buffer = buf;

PARRAY_BUFFER_HOLDER is just a type that holds the thing to be free (or
object containing things to be released), and the persistent reference that
has been made weak...

struct arrayBufferHolder {
void *buffer;
Persistent o;
};



On Thu, Nov 16, 2017 at 9:56 AM, Jean-Marc Le Roux <jeanmarc.ler...@aerys.in
> wrote:

> Node offers a C++ Clss extention ObjectWrap
>
>
> Thanks !
> It is related to node. Yet I'm not sure how I'm supposed to use ObjectWrap.
>
> I understand I have to create my own class that extends ObjectWrap and
> implement a proper destructor.
> Then I'll instanciate that class to wrap my Local. But how do I
> manage such instance?
> If I don't keep it somewhere, it will be destructed.
> If I keep it around, then I'm keeping references to potentially
> deallocated memory.
>
> It feels like I end up with the same problem...
>
> 2017-11-16 18:36 GMT+01:00 J Decker <d3c...@gmail.com>:
>
>>
>>
>> On Thu, Nov 16, 2017 at 1:24 AM, Jean-Marc Le Roux <
>> jeanmarc.ler...@aerys.in> wrote:
>>
>>> I assume you're storing references to the objects as Persistent?
>>>
>>>
>>> Nope. You've got the whole code up there.
>>> So if I understand correctly:
>>>
>>>- the objects I need to keep track of the lifecycle should be made
>>>Persistent ;
>>>- all the other values can be set as Local ;
>>>- I should set the weak callback using MakeWeak ;
>>>- callback will be called when such object is GCed and I can free my
>>>C/C++ memory then.
>>>
>>> Is that correct ?
>>>
>>
>> Yes.  I sthis perhaps related to Node?
>> Node offers a C++ Clss extention ObjectWrap
>>
>> https://nodejs.org/api/addons.html#addons_wrapping_c_objects
>> https://github.com/nodejs/node/blob/master/src/node_object_wrap.h
>>
>> which simplifies that whole process... when the object is GC'd the class
>> destructor will get called so you can release values there.
>>
>>
>>
>>>
>>> 2017-11-15 19:50 GMT+01:00 J Decker <d3c...@gmail.com>:
>>>
>>>> I assume you're storing references to the objects as Persistent?  All
>>>> you need to do then is call SetWeak() https://v8docs.nodes
>>>> ource.com/node-0.10/d2/d78/classv8_1_1_persistent.html
>>>> void MakeWeak (void *parameters, WeakReferenceCallback callback)
>>>>
>>>> the callback is called when the object is GC'd.
>>>>
>>>>
>>>> On Wed, Nov 15, 2017 at 8:37 AM, Jean-Marc Le Roux <
>>>> jeanmarc.ler...@aerys.in> wrote:
>>>>
>>>>> So I've found a solution to make things lazy: I set an accessor
>>>>> instead of decoding/setting the actual value.
>>>>>
>>>>> void
>>>>> getter(Local property, const PropertyCallbackInfo& info)
>>>>> {
>>>>> Isolate* isolate = info.GetIsolate();
>>>>>
>>>>>   const bson_t* document = reinterpret_cast<bson_t*>(
>>>>> info.This()
>>>>> ->Get(String::NewFromUtf8(isolate, "__bson_document_ptr"))
>>>>> ->ToInt32()->Value()
>>>>> );
>>>>>
>>

Re: [v8-users] BSON to v8::Object performance issue

2017-11-16 Thread J Decker
On Thu, Nov 16, 2017 at 1:24 AM, Jean-Marc Le Roux <jeanmarc.ler...@aerys.in
> wrote:

> I assume you're storing references to the objects as Persistent?
>
>
> Nope. You've got the whole code up there.
> So if I understand correctly:
>
>- the objects I need to keep track of the lifecycle should be made
>Persistent ;
>- all the other values can be set as Local ;
>- I should set the weak callback using MakeWeak ;
>- callback will be called when such object is GCed and I can free my
>C/C++ memory then.
>
> Is that correct ?
>

Yes.  I sthis perhaps related to Node?
Node offers a C++ Clss extention ObjectWrap

https://nodejs.org/api/addons.html#addons_wrapping_c_objects
https://github.com/nodejs/node/blob/master/src/node_object_wrap.h

which simplifies that whole process... when the object is GC'd the class
destructor will get called so you can release values there.



>
> 2017-11-15 19:50 GMT+01:00 J Decker <d3c...@gmail.com>:
>
>> I assume you're storing references to the objects as Persistent?  All you
>> need to do then is call SetWeak() https://v8docs.nodes
>> ource.com/node-0.10/d2/d78/classv8_1_1_persistent.html
>> void MakeWeak (void *parameters, WeakReferenceCallback callback)
>>
>> the callback is called when the object is GC'd.
>>
>>
>> On Wed, Nov 15, 2017 at 8:37 AM, Jean-Marc Le Roux <
>> jeanmarc.ler...@aerys.in> wrote:
>>
>>> So I've found a solution to make things lazy: I set an accessor instead
>>> of decoding/setting the actual value.
>>>
>>> void
>>> getter(Local property, const PropertyCallbackInfo& info)
>>> {
>>> Isolate* isolate = info.GetIsolate();
>>>
>>>   const bson_t* document = reinterpret_cast<bson_t*>(
>>> info.This()
>>> ->Get(String::NewFromUtf8(isolate, "__bson_document_ptr"))
>>> ->ToInt32()->Value()
>>> );
>>>
>>> char key[255];
>>> property->ToString(isolate)->WriteUtf8(key, 255);
>>>
>>> bson_iter_t iter;
>>> bson_iter_init(, document);
>>> // FIXME: index the property so we don't have to find it
>>> bson_iter_find(, key);
>>>
>>> // FIXME: replace the accessor with the deserialized value
>>>
>>> info.GetReturnValue().Set(iterator_to_value(isolate, ));
>>> }
>>>
>>> Local
>>> fill_object(Isolate* isolate, Local& obj, const bson_t* document)
>>> {
>>> obj->Set(
>>> String::NewFromUtf8(isolate, "__bson_document_ptr"),
>>> Int32::New(isolate, reinterpret_cast(document))
>>> );
>>>
>>> bson_iter_t iter;
>>> if (bson_iter_init(, document))
>>> {
>>> while (bson_iter_next())
>>> {
>>> const char* key = bson_iter_key();
>>>
>>> if (!obj->Has(String::NewFromUtf8(isolate,
>>> key)))
>>> {
>>> obj->SetAccessor(
>>> isolate->GetCurrentContext(),
>>> String::NewFromUtf8(isolate, key),
>>> 
>>> );
>>> }
>>> }
>>> }
>>> }
>>>
>>> The secret sauce is to :
>>>
>>>- keep the original data (the bson_t) allocated
>>>- store the corresponding pointer in a v8::Object
>>>
>>> But now I have a memory leak because those pointers will never be freed.
>>> How can I know when the Object will be disposed by the GC?
>>>
>>> Thanks,
>>>
>>> --
>>> --
>>> 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 a topic in the
>> Google Groups "v8-users" group.
>> To unsubscribe from this topic, visit https://g

Re: [v8-users] BSON to v8::Object performance issue

2017-11-15 Thread J Decker
I assume you're storing references to the objects as Persistent?  All you
need to do then is call SetWeak()
https://v8docs.nodesource.com/node-0.10/d2/d78/classv8_1_1_persistent.html
void MakeWeak (void *parameters, WeakReferenceCallback callback)

the callback is called when the object is GC'd.


On Wed, Nov 15, 2017 at 8:37 AM, Jean-Marc Le Roux  wrote:

> So I've found a solution to make things lazy: I set an accessor instead of
> decoding/setting the actual value.
>
> void
> getter(Local property, const PropertyCallbackInfo& info)
> {
> Isolate* isolate = info.GetIsolate();
>
>   const bson_t* document = reinterpret_cast(
> info.This()
> ->Get(String::NewFromUtf8(isolate, "__bson_document_ptr"))
> ->ToInt32()->Value()
> );
>
> char key[255];
> property->ToString(isolate)->WriteUtf8(key, 255);
>
> bson_iter_t iter;
> bson_iter_init(, document);
> // FIXME: index the property so we don't have to find it
> bson_iter_find(, key);
>
> // FIXME: replace the accessor with the deserialized value
>
> info.GetReturnValue().Set(iterator_to_value(isolate, ));
> }
>
> Local
> fill_object(Isolate* isolate, Local& obj, const bson_t* document)
> {
> obj->Set(
> String::NewFromUtf8(isolate, "__bson_document_ptr"),
> Int32::New(isolate, reinterpret_cast(document))
> );
>
> bson_iter_t iter;
> if (bson_iter_init(, document))
> {
> while (bson_iter_next())
> {
> const char* key = bson_iter_key();
>
> if (!obj->Has(String::NewFromUtf8(isolate, key)))
> {
> obj->SetAccessor(
> isolate->GetCurrentContext(),
> String::NewFromUtf8(isolate, key),
> 
> );
> }
> }
> }
> }
>
> The secret sauce is to :
>
>- keep the original data (the bson_t) allocated
>- store the corresponding pointer in a v8::Object
>
> But now I have a memory leak because those pointers will never be freed.
> How can I know when the Object will be disposed by the GC?
>
> Thanks,
>
> --
> --
> 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] internal fields

2017-11-06 Thread J Decker
On Mon, Nov 6, 2017 at 12:47 PM, Jakob Kummerow 
wrote:

> 3. What difference does it make to v8 if the internal field is an aligned
>>> pointer or not? Is the ability to set/get aligned pointers a consistency
>>> check so assumptions can be made? Does the interface check the alignment?
>>> (Not critical for me, I don't think, but I'd like to understand.)
>>>
>>
>> I doubt it matters... basically internal fields seem to be user-data
>> fields that store the value so your user code can later retrieve it.
>> Internally I wouldn't expect V8 to ever actually do anything with those
>> fields. Since they are usually pointers that are stored, aligned buffers
>> will be more optimal.
>>
>
> It actually does matter, and the interface does check for alignment. The
> reason is that V8 relies on those pointers being aligned: it uses this fact
> as part of the mechanism for deciding to ignore them.
>

Well 'aligned' is pretty generous... it only requires being 16 bit
aligned...  (2 byte)


from https://github.com/v8/v8/blob/master/src/api.cc#L1186

const int kSmiTag = 0;
const int kSmiTagSize = 1;
const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;

#define HAS_SMI_TAG(value) \
  ((reinterpret_cast(value) & ::i::kSmiTagMask) == ::i::kSmiTag)

bool Object::IsSmi() const { return HAS_SMI_TAG(this); }

Utils::ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");

Which since this is ObjectWrap feature, it's passed a pointer to a class,
which I would imagine 'new' will return a 4 or 8 byte aligned pointer; but
on further research there is no guarantee.

-- 
> --
> 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] internal fields

2017-11-04 Thread J Decker
On Sat, Nov 4, 2017 at 9:29 AM, Bruce MacNaughton 
wrote:

> I am new to Nan, V8, and C++ (so if I haven't put a big enough target on
> my back I don't know what else I can add). I've written a lot of JavaScript
> and, in the past, C, assembler, and kernel mode code, so hopefully the
> bulls-eye is a little smaller now.
>
> I'm working with an existing code base and am trying to understand why
> things were done the way they were. It uses Nan to create an addon for
> nodejs. I'm hoping someone here can help me understand some pieces that
> escape me.
>

Nan is really a nodejs thing, and not V8... so this is sort of the wrong
place for these questions...


>
> 1. The code sets internal field count for each class - sometimes to 1 and
> sometimes to 2 - but never invokes "setInternalField()" or
> "getInternalField()". Is there some reason, possibly historical, that
> "setInternalFieldCount()" needed to be called to set a value? The way I
> have interpreted what I've read is that my code needs to set and get the
> value explicitly, so setting a value but never storing anything there makes
> no sense to me.
>
>   // Prepare constructor template
>  v8::Local ctor = Nan::New
> (New);
>  ctor->InstanceTemplate()->SetInternalFieldCount(2);
>  ctor->SetClassName(Nan::New("MyClass").ToLocalChecked());
>
>
Does it use Wrap and/or as classes subclassed with ObjectWrap?  Wrap uses
internal field 0 to store the class so it can be later unwrapped from the
V8 object.
https://github.com/nodejs/node/blob/master/src/node_object_wrap.h#L75 (near
that is also SetWeak reference)


> 2. Given that I'm storing something in internal fields, my understanding
> is that I need to free any resources (memory, etc.) that are used by the
> internal field if the object is GC'd. Doing that in the destructor seems to
> be the right way to handle that. Is that all there is to it?
>
> the destructor is really too late, at the point the destructor is called,
the Object holding it would have also disappeared If the destructor is
getting called, it's probably because of an ObjectWrapped thing
disappearing, which internally stores the object in the class as a
Persistent<> that is SetWeak()'d.  SetWeak takes a callback which is called
when the object is GC'd.


> 3. What difference does it make to v8 if the internal field is an aligned
> pointer or not? Is the ability to set/get aligned pointers a consistency
> check so assumptions can be made? Does the interface check the alignment?
> (Not critical for me, I don't think, but I'd like to understand.)
>
>
I dooubt it matters... basically internal fields seem to be user-data
fields that store the value so your user code can later retrieve it.
Internally I wouldn't expect V8 to ever actually do anything with those
fields. Since they are usually pointers that are stored, aligned buffers
will be more optimal.


>
>
>
>
> --
> --
> 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] Build V8 6.x on Windows with VS2013

2017-11-03 Thread J Decker
On Fri, Nov 3, 2017 at 3:49 PM, Ivan Pizhenko 
wrote:

> Actually, from these ones:
> {"chromium_version": "56.0.2924.121", "v8_version": "5.6.326.55"}
> {"chromium_version": "57.0.2987.154", "v8_version": "5.7.492.73"}
> {"chromium_version": "58.0.3029.125", "v8_version": "5.8.283.38"}
> only V8 5.6 is buildable with VS2013.
>
> did you actually try?  Or just assume?  or just take notes from docs?
I'd imagine it doesn't have a lot of differences that would cause it to
break on slightly older VS versions... although not officially supported.
https://github.com/v8/v8/wiki/Building%20with%20Gyp says 2013 is a compiler
that you can use (no mention of 2017 though; maybe just outdated?)


> 2017-11-01 17:12 GMT+02:00 Ivan Pizhenko :
>
>> Thank you!
>>
>> 2017-11-01 13:26 GMT+02:00 Ben Noordhuis :
>>
>>> On Wed, Nov 1, 2017 at 1:23 AM, Ivan P.  wrote:
>>> > Hello, I want to update V8 used in my application from the version 5.3
>>> to a
>>> > some latest stable 6.x
>>> > The possible issue is that my application is built with a bit outdated
>>> > nowadays Visual Studio 2013 and in the meantime I cannot upgrade to any
>>> > later VS version due to some other pending dependencies.
>>> > Can anyone of V8 developers, or just someone proficient in the topic,
>>> tell
>>> > me, whether latest V8 6.x still can be built with VS2013?
>>> > (I could do it for the version I use now - some 5.3), and if not, what
>>> is
>>> > the last version of V8 that can be built with VS 2013?
>>>
>>> I'm fairly sure that 2013 is not tested or supported anymore, so the
>>> answer to your first question is 'probably not.'
>>>
>>> The answer to your second question is V8 5.8 or thereabouts.
>>>
>>> --
>>> --
>>> v8-users mailing list
>>> v8-users@googlegroups.com
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "v8-users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/v8-users/7G1IsFY3QLI/unsubscribe.
>>> To unsubscribe from this group and all its topics, 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] InstanceTemplate, SetAccessor versus SetNativeDataProperty

2017-10-25 Thread J Decker


On Wednesday, October 25, 2017 at 12:55:36 AM UTC-7, Toon Verwaest wrote:
>
> As Ben stated, --disable-old-api-accessors makes them behave the same; but 
> it indeed makes SetAccessor work like SetNativeDataProperty.
>
> The reason is that SetAccessor creates a pseudo-data-property that's 
> backed by accessors: Object.getOwnPropertyDescriptor(o, "p") will return 
> something that looks like a data property, not like an accessor. Data 
> properties are supposed to behave differently when on the prototype chain 
> than accessors. If there's a getter, we should call into it. If there's a 
> setter, however, we shouldn't call it. We should only check whether data 
> properties on the prototype chain are read-only, and thrown an exception if 
> they are. That's how data properties work.
>
> If you want something similar to the old-style SetAccessor behavior, you 
> should instead use SetAccessorProperty. That creates an actual 
> getter/setter pair. That setter will be called through the prototype chain 
> as well, just like other accessors in JS.
>
>
Thank you :)  After updating to SetAccessorProperty and setting ReadOnly as 
appropriate I get [getter] or [getter/setter] notations on them which is 
what I would expect (rather than calling them with non-instance This()s )
 

> The old behavior for SetAccessor is a v8-only invention that looks like a 
> data property but behaves like an accessor; which not only adds unnecessary 
> complexity, but is actually impossible to implement correctly in certain 
> cases.
>
> HTH,
> Toon
>
> On Tue, Oct 24, 2017 at 5:49 PM J Decker <d3c...@gmail.com > 
> wrote:
>
>>
>>
>> On Tuesday, October 24, 2017 at 7:38:44 AM UTC-7, Ben Noordhuis wrote:
>>
>>> On Tue, Oct 24, 2017 at 3:32 PM, J Decker <d3c...@gmail.com> wrote: 
>>> > 
>>> > On Tuesday, October 24, 2017 at 3:40:31 AM UTC-7, Ben Noordhuis wrote: 
>>> >> 
>>> >> On Tue, Oct 24, 2017 at 5:53 AM, J Decker <d3c...@gmail.com> wrote: 
>>> >> > 
>>> >> > On Thursday, August 7, 2014 at 3:52:53 PM UTC-7, Ben Noordhuis 
>>> wrote: 
>>> >> >> 
>>> >> >> On Fri, Aug 8, 2014 at 12:10 AM, Flying Jester <
>>> foolki...@gmail.com> 
>>> >> >> wrote: 
>>> >> >> > What precisely is the difference between using SetAccessor and 
>>> >> >> > SetNativeDataProperty? 
>>> >> >> 
>>> >> >> Nothing, as far as I know.  The order of arguments is different 
>>> but 
>>> >> >> they have identical implementations. 
>>> >> > 
>>> >> > They are not exactly the same...  I've been using 
>>> SetNativeDataProperty, 
>>> >> > which works for getters, but when i started to use it for a setter, 
>>> V8 
>>> >> > ended 
>>> >> > up setting a property on the object instead of calling the setter. 
>>> >> > Changing 
>>> >> > to SetAccessor allows the setter to be called correctly. 
>>> >> > 
>>> >> > And while I realize this is a very old thread; it's about the only 
>>> one 
>>> >> > that 
>>> >> > shows up for 'SetNativeDataProperty vs SetAccessor' 
>>> >> > 
>>> >> > I can't find any other information that would indicate that 
>>> >> > setnativedataproperty shouldn't or doesn't work; other than my 
>>> code. 
>>> >> 
>>> >> Blast from the past! 
>>> >> 
>>> >> I believe what I wrote still holds (or holds again) if you start V8 
>>> >> with `--disable_old_api_accessors`.  It's currently off by default 
>>> but 
>>> >> that will likely change someday. 
>>> > 
>>> > 
>>> > That option makes SetAccessor setter not work.  It creates a property 
>>> on the 
>>> > object instead of calling the setter. 
>>> > 
>>> > psiTemplate2->PrototypeTemplate()->SetAccessor( String::NewFromUtf8( 
>>> > isolate, "text" ) 
>>> > , ControlObject::getControlText, ControlObject::setControlText ); 
>>> > 
>>> > So that's discouraging 
>>>
>>> With `--disable_old_api_accessors` they are quite literally the same 
>>> implementation.  Something else must be going on.  Out-of-date V8 
>>> version? 
>>>
>>
>> M:\javascript\vfs\native>node
>> > 

Re: [v8-users] Automatic To String of fields

2017-10-24 Thread J Decker


On Tuesday, October 24, 2017 at 7:32:31 PM UTC-7, J Decker wrote:
>
>
>
> On Tuesday, October 24, 2017 at 10:25:14 AM UTC-7, Ben Noordhuis wrote:
>>
>> On Tue, Oct 24, 2017 at 6:12 PM, J Decker <d3c...@gmail.com> wrote: 
>> > 
>> > On Tuesday, October 24, 2017 at 7:35:20 AM UTC-7, Ben Noordhuis wrote: 
>> >> 
>> >> On Tue, Oct 24, 2017 at 3:27 PM, J Decker <d3c...@gmail.com> wrote: 
>> >> > Is there a way to make a C++ class that has set accessors on the 
>> >> > prototype 
>> >> > to get its data logged? 
>> >> > 
>> >> > so like 
>> >> > var color = new Color( "white" ); 
>> >> > console.log( color ): 
>> >> 
>> >> I think you are asking about the difference between 
>> >> PropertyCallbackInfo::This() and PropertyCallbackInfo::Holder(). 
>> >> The first is the instance object, the second the prototype object. 
>> >> 
>> >> (If it's not that, please clarify what "gets its data logged" means.) 
>> > 
>> > 
>> > No... I'm just asking if there's a way to get console.log to log 
>> > setters/getters configured on the object, similar to how it will log 
>> > properties directly on an object. 
>> > and re the this/holder differneces... the documentation in v8.h 
>> describes 
>> > this and holder pretty well now 
>> > 
>> >> 
>> >> 
>> >> > Also, I added a toString() method to the prototype, but apparently I 
>> >> > have to 
>> >> > append it to a string (as in console.log( ""+color ) } or call it 
>> >> > explicitly... console.log( color.toString() ) 
>> >> 
>> >> Yes.  Did you expect something else? 
>> > 
>> > 
>> > Well another thread said I shouldn't have to append it to a string... 
>>  I 
>> > mean doesn't console.log attempt to convert arguments to string anyway? 
>>  I 
>> > know it doesn't in a browser, because you get an arrow you can use to 
>> expand 
>> > an object... but this is using node... hmm maybe it's more of a node 
>> issue; 
>> > I suppose if I were using electron or nwjs I would get the object 
>> logged 
>> > with an expansion arrow... 
>>
>> Right.  Yes, the console.log() in Node.js goes well beyond simple 
>> stringification. It also doesn't print non-enumerable properties[0] or 
>> properties from the prototype chain. 
>>
>> [0] `console.log(util.inspect(obj, {showHidden: true}))` will, though. 
>>
>
Oh my bad, I misread 'or properties from the prototype chain' 

-- 
-- 
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] Automatic To String of fields

2017-10-24 Thread J Decker


On Tuesday, October 24, 2017 at 10:25:14 AM UTC-7, Ben Noordhuis wrote:
>
> On Tue, Oct 24, 2017 at 6:12 PM, J Decker <d3c...@gmail.com > 
> wrote: 
> > 
> > On Tuesday, October 24, 2017 at 7:35:20 AM UTC-7, Ben Noordhuis wrote: 
> >> 
> >> On Tue, Oct 24, 2017 at 3:27 PM, J Decker <d3c...@gmail.com> wrote: 
> >> > Is there a way to make a C++ class that has set accessors on the 
> >> > prototype 
> >> > to get its data logged? 
> >> > 
> >> > so like 
> >> > var color = new Color( "white" ); 
> >> > console.log( color ): 
> >> 
> >> I think you are asking about the difference between 
> >> PropertyCallbackInfo::This() and PropertyCallbackInfo::Holder(). 
> >> The first is the instance object, the second the prototype object. 
> >> 
> >> (If it's not that, please clarify what "gets its data logged" means.) 
> > 
> > 
> > No... I'm just asking if there's a way to get console.log to log 
> > setters/getters configured on the object, similar to how it will log 
> > properties directly on an object. 
> > and re the this/holder differneces... the documentation in v8.h 
> describes 
> > this and holder pretty well now 
> > 
> >> 
> >> 
> >> > Also, I added a toString() method to the prototype, but apparently I 
> >> > have to 
> >> > append it to a string (as in console.log( ""+color ) } or call it 
> >> > explicitly... console.log( color.toString() ) 
> >> 
> >> Yes.  Did you expect something else? 
> > 
> > 
> > Well another thread said I shouldn't have to append it to a string...  I 
> > mean doesn't console.log attempt to convert arguments to string anyway? 
>  I 
> > know it doesn't in a browser, because you get an arrow you can use to 
> expand 
> > an object... but this is using node... hmm maybe it's more of a node 
> issue; 
> > I suppose if I were using electron or nwjs I would get the object logged 
> > with an expansion arrow... 
>
> Right.  Yes, the console.log() in Node.js goes well beyond simple 
> stringification. It also doesn't print non-enumerable properties[0] or 
> properties from the prototype chain. 
>
> [0] `console.log(util.inspect(obj, {showHidden: true}))` will, though. 
>

That could be useful thank you for the hint.

Doesn't help for logging an instance of an object template.  It does show 
the properties in an object template though  sack.Image.colors.white is 
an instance of a sack.Image.Color (need to rename the internal name text).  

console.log( "got", util.inspect(sack.Image.colors.white, {showHidden: 
true}) );
   got sack.Image.color {}

console.log( "color:",  ""+sack.Image.colors.white);
color: {r:255,g:255,b:255,a:255}

var x = sack.Image.Color( {r:50,g:50,b:255,a:255} );
console.log( "color:",  Object.keys(Object.getPrototypeOf( x )), ""+x, 
x.toString() );
color: [ 'a', 'b', 'g', 'r', 'toString' ] {r:50,g:50,b:255,a:255} 
{r:50,g:50,b:255,a:255}


console.log( "got", util.inspect(sack.Image.Color, {showHidden: true}) 
);
 got { [Function: sack.Image.color]
   [length]: 0, [name]: 'sack.Image.color', [arguments]: null,  
[caller]: null,   [prototype]: 
sack.Image.color {
  a: undefined,  b: undefined,   g: undefined,  r: undefined,
  toString: 
   { [Function: toString]
 [length]: 0, name]: 'toString',  [arguments]: null, 
[caller]: null,  [prototype]: [Object] },
  [constructor]: [Circular] } }

logging the getters though returns 'undefined' because it's logging the 
prototype and not an instance of the prototype ( 'this' isn't a ColorObject 
)

-- 
-- 
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] Automatic To String of fields

2017-10-24 Thread J Decker


On Tuesday, October 24, 2017 at 7:35:20 AM UTC-7, Ben Noordhuis wrote:
>
> On Tue, Oct 24, 2017 at 3:27 PM, J Decker <d3c...@gmail.com > 
> wrote: 
> > Is there a way to make a C++ class that has set accessors on the 
> prototype 
> > to get its data logged? 
> > 
> > so like 
> > var color = new Color( "white" ); 
> > console.log( color ): 
>
> I think you are asking about the difference between 
> PropertyCallbackInfo::This() and PropertyCallbackInfo::Holder(). 
> The first is the instance object, the second the prototype object. 
>
> (If it's not that, please clarify what "gets its data logged" means.) 
>
 
No... I'm just asking if there's a way to get console.log to log 
setters/getters configured on the object, similar to how it will log 
properties directly on an object.
and re the this/holder differneces... the documentation in v8.h describes 
this and holder pretty well now
 

>
> > Also, I added a toString() method to the prototype, but apparently I 
> have to 
> > append it to a string (as in console.log( ""+color ) } or call it 
> > explicitly... console.log( color.toString() ) 
>
> Yes.  Did you expect something else? 
>

Well another thread said I shouldn't have to append it to a string...  I 
mean doesn't console.log attempt to convert arguments to string anyway?  I 
know it doesn't in a browser, because you get an arrow you can use to 
expand an object... but this is using node... hmm maybe it's more of a node 
issue; I suppose if I were using electron or nwjs I would get the object 
logged with an expansion arrow... 

-- 
-- 
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] InstanceTemplate, SetAccessor versus SetNativeDataProperty

2017-10-24 Thread J Decker


On Tuesday, October 24, 2017 at 7:38:44 AM UTC-7, Ben Noordhuis wrote:
>
> On Tue, Oct 24, 2017 at 3:32 PM, J Decker <d3c...@gmail.com > 
> wrote: 
> > 
> > On Tuesday, October 24, 2017 at 3:40:31 AM UTC-7, Ben Noordhuis wrote: 
> >> 
> >> On Tue, Oct 24, 2017 at 5:53 AM, J Decker <d3c...@gmail.com> wrote: 
> >> > 
> >> > On Thursday, August 7, 2014 at 3:52:53 PM UTC-7, Ben Noordhuis wrote: 
> >> >> 
> >> >> On Fri, Aug 8, 2014 at 12:10 AM, Flying Jester <foolki...@gmail.com> 
>
> >> >> wrote: 
> >> >> > What precisely is the difference between using SetAccessor and 
> >> >> > SetNativeDataProperty? 
> >> >> 
> >> >> Nothing, as far as I know.  The order of arguments is different but 
> >> >> they have identical implementations. 
> >> > 
> >> > They are not exactly the same...  I've been using 
> SetNativeDataProperty, 
> >> > which works for getters, but when i started to use it for a setter, 
> V8 
> >> > ended 
> >> > up setting a property on the object instead of calling the setter. 
> >> > Changing 
> >> > to SetAccessor allows the setter to be called correctly. 
> >> > 
> >> > And while I realize this is a very old thread; it's about the only 
> one 
> >> > that 
> >> > shows up for 'SetNativeDataProperty vs SetAccessor' 
> >> > 
> >> > I can't find any other information that would indicate that 
> >> > setnativedataproperty shouldn't or doesn't work; other than my code. 
> >> 
> >> Blast from the past! 
> >> 
> >> I believe what I wrote still holds (or holds again) if you start V8 
> >> with `--disable_old_api_accessors`.  It's currently off by default but 
> >> that will likely change someday. 
> > 
> > 
> > That option makes SetAccessor setter not work.  It creates a property on 
> the 
> > object instead of calling the setter. 
> > 
> > psiTemplate2->PrototypeTemplate()->SetAccessor( String::NewFromUtf8( 
> > isolate, "text" ) 
> > , ControlObject::getControlText, ControlObject::setControlText ); 
> > 
> > So that's discouraging 
>
> With `--disable_old_api_accessors` they are quite literally the same 
> implementation.  Something else must be going on.  Out-of-date V8 
> version? 
>

M:\javascript\vfs\native>node
> process.version
'v8.4.0'
> process.versions
{ http_parser: '2.7.0',
  node: '8.4.0',
  v8: '6.0.286.52',
  uv: '1.13.1',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  nghttp2: '1.22.0',
  openssl: '1.0.2l',
  icu: '59.1',
  unicode: '9.0',
  cldr: '31.0.1',
  tz: '2017b' } 

I doubt it.  It's not absolute bleeding edge, but it's pretty new.

I was going to include the whole thing I'm trying to test, but expect that 
to fail so here's a super simple test

https://github.com/d3x0r/test-accessor

It sets a SetAccessor called 'text' and a SetNativeDataProperty called 
'native'

to build
npm install .  

test1 : ( only setter called is SetAccessor settter )
npm test

(sample output) 
> node test.js

plugin.cc: getter called... default value
Default: default value
plugin.cc: setter called... with newText
plugin.cc: getter called... newText
Default: [] newText
plugin.cc: getter called... newText
Default: newText
Default: [ 'native' ] nativeText


test2 : (passes --disable-old-api-accessors  which makes neither setter get 
called )
npm run test2

(sample output)
> node --disable-old-api-accessors test.js

plugin.cc: getter called... default value
Default: default value
Default: [ 'text' ] newText
plugin.cc: getter called... default value
Default: default value
Default: [ 'text', 'native' ] nativeText





- what I would have sent -

This is a node plugin - https://github.com/d3x0r/sack.vfs the new features 
I'm extending it with I can only confirm work under Windows.

https://github.com/d3x0r/sack.vfs/blob/master/src/gui/sack_psi_module.cc#L415  
configures accessor on prototype here

Which is tested with this 
line... https://github.com/d3x0r/sack.vfs/blob/master/tests/sack_test4.js#L28  
which should change the text in the resulting gui.



-- 
-- 
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] InstanceTemplate, SetAccessor versus SetNativeDataProperty

2017-10-24 Thread J Decker


On Tuesday, October 24, 2017 at 3:40:31 AM UTC-7, Ben Noordhuis wrote:
>
> On Tue, Oct 24, 2017 at 5:53 AM, J Decker <d3c...@gmail.com > 
> wrote: 
> > 
> > On Thursday, August 7, 2014 at 3:52:53 PM UTC-7, Ben Noordhuis wrote: 
> >> 
> >> On Fri, Aug 8, 2014 at 12:10 AM, Flying Jester <foolki...@gmail.com> 
> >> wrote: 
> >> > What precisely is the difference between using SetAccessor and 
> >> > SetNativeDataProperty? 
> >> 
> >> Nothing, as far as I know.  The order of arguments is different but 
> >> they have identical implementations. 
> > 
> > They are not exactly the same...  I've been using SetNativeDataProperty, 
> > which works for getters, but when i started to use it for a setter, V8 
> ended 
> > up setting a property on the object instead of calling the setter. 
>  Changing 
> > to SetAccessor allows the setter to be called correctly. 
> > 
> > And while I realize this is a very old thread; it's about the only one 
> that 
> > shows up for 'SetNativeDataProperty vs SetAccessor' 
> > 
> > I can't find any other information that would indicate that 
> > setnativedataproperty shouldn't or doesn't work; other than my code. 
>
> Blast from the past! 
>
> I believe what I wrote still holds (or holds again) if you start V8 
> with `--disable_old_api_accessors`.  It's currently off by default but 
> that will likely change someday. 
>

That option makes SetAccessor setter not work.  It creates a property on 
the object instead of calling the setter.

psiTemplate2->PrototypeTemplate()->SetAccessor( String::NewFromUtf8( 
isolate, "text" )
, ControlObject::getControlText, ControlObject::setControlText );

So that's discouraging

-- 
-- 
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] Automatic To String of fields

2017-10-24 Thread J Decker
Is there a way to make a C++ class that has set accessors on the prototype 
to get its data logged?

so like 
var color = new Color( "white" );
console.log( color ): 

and have it show sack.Image.Color { r: 255, g:255, b:255, a:255 } (or some 
order therteof instead of just 
sack.Image.Color {} 

?
Also, I added a toString() method to the prototype, but apparently I have 
to append it to a string (as in console.log( ""+color ) } or call it 
explicitly... console.log( color.toString() )

Accesors that are on the object, and not in the prototype do get logged... 
(IIRC)

-- 
-- 
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] InstanceTemplate, SetAccessor versus SetNativeDataProperty

2017-10-23 Thread J Decker


On Thursday, August 7, 2014 at 3:52:53 PM UTC-7, Ben Noordhuis wrote:
>
> On Fri, Aug 8, 2014 at 12:10 AM, Flying Jester  > wrote: 
> > What precisely is the difference between using SetAccessor and 
> > SetNativeDataProperty? 
>
> Nothing, as far as I know.  The order of arguments is different but 
> they have identical implementations. 
>
They are not exactly the same...  I've been using SetNativeDataProperty, 
which works for getters, but when i started to use it for a setter, V8 
ended up setting a property on the object instead of calling the setter.  
Changing to SetAccessor allows the setter to be called correctly.

And while I realize this is a very old thread; it's about the only one that 
shows up for 'SetNativeDataProperty vs SetAccessor'

I can't find any other information that would indicate that 
setnativedataproperty shouldn't or doesn't work; other than my code.

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