Re: [v8-users] v8::ScriptOrigin line/column offset

2020-11-12 Thread 'Simon Zünd' via v8-users
This is used e.g. when your script is inline in 

Re: [v8-users] Reusing v8 context

2020-11-02 Thread 'Simon Zünd' via v8-users
My guess is that in your V8ContextCreate function you also need a temporary
HandleScope before you can make a global out of the context:

v8::HandleScope handle_scope(engine->isolate);

On Mon, Nov 2, 2020 at 10:36 AM Marco Bambini 
wrote:

> Dear All,
> I am a C developer quite new to v8 (I have limited c++ knowledge).
> Sorry if I ask very basic questions.
>
> I have a C application that need to execute some js code in different
> times preserving the same context.
>
> My code looks like:
> *Header file*
> *=*
> #ifdef __cplusplus
> extern "C" {
> #endif
> #include 
>
> typedef struct V8Engine V8Engine;
> typedef struct V8Context V8Context;
> typedef struct V8Value V8Value;
>
> V8Engine* V8EngineInit (const char *path);
> void  V8EngineFree (V8Engine *engine);
> V8Context* V8ContextCreate (V8Engine *engine);
> void V8ContextFree (V8Context *context);
> V8Value* V8ExecuteScript (V8Context *context, const char *script);
> bool V8ValueIsError (V8Value *value);
>
> #ifdef __cplusplus
>
> }
>
> #endif
>
> #endif
>
>
>
> *C++ file*
> *==*
> #include "libplatform/libplatform.h"
> #include "v8.h"
> #include "c8.h"
>
> struct V8Engine {
> std::unique_ptr platform;
> v8::Isolate::CreateParams create_params;
> v8::Isolate *isolate;
> v8::Isolate::Scope *isolate_scope;
>
> };
>
> struct V8Context {
>  V8Engine *engine;
>  v8::Global *context;
> };
>
> struct V8Value {
>
> };
>
>
>
> // MARK: -
>
> extern "C" {
>
> V8Engine* V8EngineInit (const char *path) {
> V8Engine *engine = (V8Engine *)calloc(1, sizeof(V8Engine));
> if (!engine) return nullptr;
>
> // Initialize V8
> v8::V8::InitializeICUDefaultLocation(path);
> v8::V8::InitializeExternalStartupData(path);
> engine->platform = v8::platform::NewDefaultPlatform();
>
> v8::V8::InitializePlatform(engine->platform.get());
> v8::V8::Initialize();
>
> engine->create_params.array_buffer_allocator =
> v8::ArrayBuffer::Allocator::NewDefaultAllocator();
> engine->isolate = v8::Isolate::New(engine->create_params);
> engine->isolate_scope = new v8::Isolate::Scope(engine->isolate);
>
> return engine;
> }
>
>
> void V8EngineFree (V8Engine *engine) {
> if (engine == NULL) return;
>
> if (engine->isolate_scope) {
> delete engine->isolate_scope;
> }
>
> if (engine->isolate) {
> engine->isolate->Dispose();
> }
>
> v8::V8::Dispose();
> v8::V8::ShutdownPlatform();
>
> if (engine->create_params.array_buffer_allocator) {
> delete engine->create_params.array_buffer_allocator;
> }
>
> engine->~V8Engine();
> free(engine);
> }
>
>
>
> V8Context* V8ContextCreate (V8Engine *engine) {
> V8Context *instance = (V8Context *)calloc(1, sizeof(V8Context));
> if (!instance) return nullptr;
>
> instance->engine = engine;
> v8::Local local_context =
> v8::Context::New(engine->isolate);
> instance->context = new v8::Global(engine->isolate,
> local_context);
>
> return instance;
> }
>
> void V8ContextFree (V8Context *context) {
> delete context->context;
> context->~V8Context();
> free(context);
> }
>
>
>
> V8Value* V8ExecuteScript (V8Context *instance, const char *script) {
> // Create a stack-allocated handle scope
> v8::HandleScope handle_scope(instance->engine->isolate);
>
> // Enter the context for compiling and running the script
> v8::Local
> context(instance->context->Get(instance->engine->isolate));
> v8::Context::Scope context_scope(context);
>
> {
> // Create a string containing the JavaScript source code
> v8::Local source =
> v8::String::NewFromUtf8(instance->engine->isolate, script,
> v8::NewStringType::kNormal).ToLocalChecked();
>
> // Compile the source code
> v8::Local script = v8::Script::Compile(context,
> source).ToLocalChecked();
>
> // Run the script to get the result
> v8::Local result =
> script->Run(context).ToLocalChecked();
>
> // Convert the result to an UTF8 string and print it
> v8::String::Utf8Value utf8(instance->engine->isolate, result);
> printf("%s\n", *utf8);
> }
>
> return nullptr;
> }
>
>
>
> bool V8ValueIsError (V8Value *value) {
> return false;
> }
>
> }
>
> *// main C file*
> *==*
> int main (int argc, char* argv[]) {
> V8Engine *vm = V8EngineInit(argv[0]);
> V8Context *context = V8ContextCreate(vm);
>
> const char *script1 = " function js_add_elements(var1, var2) { \
> var var3 = parseInt(var1) +
> parseInt(var2); \
> var result = 'Addition of ' + var1 + ' and
> ' + var2 + ' results ' + var3; \
> return result; \
> };";
> const char *script2 = "js_add_elements(2, 3);";
> const char *script3 = "js_add_elements(4, 5);";
>
> V8ExecuteScript(context, script1);
> V8ExecuteScript(context, script2);
> 

Re: [v8-users] Stacktrace performance

2020-02-13 Thread 'Simon Zünd' via v8-users
The improvements are with respect to serializing stack traces, that is if
you access {.stack} on an error object. Performance for error creation,
that is walking the stack and collecting frames, regressed slightly since
we do some more work upfront now.

On Thu, Feb 13, 2020 at 11:33 AM Wilfried Goesgens 
wrote:

> No,
> I wanted to demonstrate the Improvements of the New V8 release, found the
> stacktraces prominent on the changelog lists; Thus I created a test to give
> me some estimates, and was disappointed with my findings ;-) If there is a
> better way to test it, please give me an example.
> Cheers,
> Willi
>
> Am Mittwoch, 12. Februar 2020 22:43:12 UTC+1 schrieb Dan Elphick:
>>
>> When I ran the test in d8 (unfortunately I didn't keep the old binaries
>> around so can't quickly verify) I saw at most a 10% difference between 7.1
>> vs 7.9.
>>
>> Is this manifesting somewhere other than in your micro benchmark? Because
>> this looks to be pretty much the worst case scenario, the function doesn't
>> do anything except construct an Error object which requires constructing a
>> stack trace and it needs to build 9 frames each time, but unless this is
>> causing a problem in real code, I'm not sure how much attention it warrants.
>>
>> On Wed, 12 Feb 2020 at 14:42, Wilfried Gösgens  wrote:
>>
>>> This 600x slowdown was inside of arangosh due to pasting - its not there
>>> anymore in the numbers of my previous post - sorry I didn't mention it
>>> explicitely.
>>>
>>> However, if you compare the numbers of my previous post, there still is
>>> an offset of ~40% which I'd still call significant?
>>>
>>> --
>>> --
>>> 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/cdeb797d-c2e3-4a8d-924f-cd484159e18f%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/0e87e1f2-1814-4c93-8057-f2982b77f20c%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/CACswSC1xws%3D_GFUASpg8Y0cDO6Cny%3D1F2CpwGOuL3sFYJpLCsw%40mail.gmail.com.


Re: [v8-users] Getting empty function names from the "StackTrace::CurrentStackTrace" method

2019-11-18 Thread 'Simon Zünd' via v8-users
+Leszek Swirski 

I am unsure what impact lazy compilation has here. There might be a weird
interaction with the stack frame cache. Does the flag "--optimize-for-size"
cause any change in the result? That flag disables the stack frame cache
(among other things).

On Tue, Nov 19, 2019 at 8:37 AM Darin Dimitrov 
wrote:

> Further narrowed it down to the "--no-lazy" runtime flag:
>
> Working:
>
> std::string flags = "--expose_gc --jitless";
> V8::SetFlagsFromString(flags.c_str(), flags.size());
>
> NOT working:
>
> std::string flags = "--expose_gc --jitless --no-lazy";
> V8::SetFlagsFromString(flags.c_str(), flags.size());
>
> Any idea why would the --no-lazy flag affect function names in stack
> frames? I need the --no-lazy flag because I noticed that it speeds up code
> cached scripts (v8::ScriptCompiler::CreateCodeCache API).
>
> On Tuesday, November 19, 2019 at 9:30:07 AM UTC+2, Darin Dimitrov wrote:
>>
>> Simon, thanks for the clarification. Does this mean that there's no
>> reliable way to get this information with the current V8 public API?
>>
>> I went ahead and wrote a simple example illustrating the issue and tried
>> running it on different platforms. And the results were surprising.
>>
>> Here's the sample code I wrote:
>>
>> Isolate::CreateParams create_params;
>> create_params.array_buffer_allocator = _;
>> Isolate* isolate = Isolate::New(create_params);
>> Isolate::Scope isolate_scope(isolate);
>> HandleScope handle_scope(isolate);
>> Local globalTemplate = ObjectTemplate::New(isolate);
>> Local context = Context::New(isolate, nullptr,
>> globalTemplate);
>> context->Enter();
>>
>> Local captureFunc = v8::Function::New(context, [](const
>> FunctionCallbackInfo& info) {
>> Isolate* isolate = info.GetIsolate();
>> Local context = isolate->GetCurrentContext();
>> Local exception =
>> Exception::Error(v8::String::NewFromUtf8(isolate, "",
>> NewStringType::kNormal, 0).ToLocalChecked()).As();
>> Local stackProperty = exception->Get(context,
>> v8::String::NewFromUtf8(isolate, "stack", NewStringType::kNormal,
>> 5).ToLocalChecked()).ToLocalChecked();
>> v8::String::Utf8Value stackStr(isolate, stackProperty);
>> printf("%s\n\n", *stackStr);
>>
>> Local stack =
>> v8::StackTrace::CurrentStackTrace(isolate, 10,
>> v8::StackTrace::StackTraceOptions::kDetailed);
>>
>> for (int i = 0; i < stack->GetFrameCount(); i++) {
>> Local frame = stack->GetFrame(isolate, i);
>> Local funcName = frame->GetFunctionName();
>> v8::String::Utf8Value str(isolate, funcName);
>> const char* name = *str;
>> printf("%s (%d:%d)\n", name, frame->GetLineNumber(),
>> frame->GetColumn());
>> }
>> }).ToLocalChecked();
>> assert(context->Global()->Set(context,
>> v8::String::NewFromUtf8(isolate, "captureTrace", NewStringType::kNormal,
>> 12).ToLocalChecked(), captureFunc).FromMaybe(false));
>>
>> std::string src =
>> "(function test() {"
>> "const viewModel = new Object();"
>> "viewModel.onTap = () => { captureTrace(); };"
>> "viewModel.onTap.apply(viewModel, []);"
>> "})();";
>> 

Re: [v8-users] Getting empty function names from the "StackTrace::CurrentStackTrace" method

2019-11-18 Thread 'Simon Zünd' via v8-users
This is a bug in our API implementation. Or better, there is a mismatch
between API and what we do internally. "Method names" and "class names" are
stored separately from function names. This can be seen here, when we
collect all the information for a single frame:
https://cs.chromium.org/chromium/src/v8/src/heap/factory.cc?rcl=e1eb815647f334a8cf970439343a8febfa9f6d11=3732

There is really no reason why this information shouldn't be made available
in the API. The only tricky thing is to come up with a better API, as some
of the getters change meaning depending whether its a JS or WASM frame and
I am not really happy with the current solution.

On Mon, Nov 18, 2019 at 4:40 PM Darin Dimitrov 
wrote:

> I am embedding V8 and trying to capture the current javascript stacktrace
> using the "v8::StackTrace::CurrentStackTrace":
>
> Isolate* isolate = info.GetIsolate();
>
> Local stack = v8::StackTrace::CurrentStackTrace(isolate, 10,
> v8::StackTrace::StackTraceOptions::kDetailed);
>
> *for* (*int* i = 0; i < stack->GetFrameCount(); i++) {
>
> Local frame = stack->GetFrame(isolate, i);
>
> Local funcName = frame->GetFunctionName();
>
> v8::String::Utf8Value str(isolate, funcName);
>
> *const* *char** name = *str;
>
> printf("%s (%d:%d)\n", name, frame->GetLineNumber(), frame->GetColumn
> ());
>
> }
>
> I have placed this code inside a custom function that I have registered to
> the global scope.
>
> Before calling my custom function, I tried logging the stack property of
> an Error object (by using : console.log(new Error().stack)) and I obtained
> the following output:
>
> Error
> at bar (file:///app/bundle.js:266:29)
> at test (file:///app/bundle.js:267:15)
> at Observable.onTap (file:///app/bundle.js:268:11)
> at Button.notify (file:///app/vendor.js:3620:32)
> at Button._emit (file:///app/vendor.js:3640:18)
> at TapHandlerImpl.tap (file:///app/vendor.js:15540:19)
>
> With the "v8::StackTrace::CurrentStackTrace" method I get:
>
> bar (266:29)
> test (267:15)
> (null) (268:11)
> (null) (3620:32)
> (null) (3640:18)
> (null) (15540:19)
>
> I am getting empty function names from some frames, while all the other
> information is present (script name, line, column numbers, ...).
>
> Do you know what might be the reason for getting empty function names?
>
> --
> --
> 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/64d9e4ca-b271-4d83-aace-753c28e193f4%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/CACswSC2PmjxdkT9qcED%2B1rHs1AkmZ3q0zTt%3D-cBfB51TTbKj6A%40mail.gmail.com.


Re: [v8-users] What do these unresolved external symbols mean when building against V8 7.8 "monolithic"?

2019-10-30 Thread 'Simon Zünd' via v8-users
Best guess, you linked the V8 monolith static library with the libstdc++
thats pulled in by "gclient sync". The project itself is linked against the
standard library of Visual Studio.

There is a GN option for this, try "use_custom_libcxx = false", which will
build V8 with the system C++ standard library.

On Wed, Oct 30, 2019 at 8:02 AM Ben Ernst  wrote:

> My platform is Windows 10, Visual C++ 2017.
>
> I build a "monolithic" V8, and try to link against it. I am buried under
> linker errors.
>
> Just a taste below, the rest are attached. Any idea what I might be doing
> wrong? I don't remotely what I have supposedly done wrong.
>
>
>
> 1>ezv8_platform.obj : error LNK2019: unresolved external symbol "class
> std::unique_ptr v8::Platform> > __cdecl v8::platform::NewDefaultPlatform(int,enum
> v8::platform::IdleTaskSupport,enum
> v8::platform::InProcessStackDumping,class std::unique_ptr v8::TracingController,struct std::default_delete v8::TracingController> >)" (?NewDefaultPlatform@platform@v8@
> @YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@std@
> @@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12
> @V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController
> @v8@@@std@@@4@@Z) referenced in function "public: __cdecl
> ezv8::Platform::Impl::Impl(void)" (??0Impl@Platform@ezv8@@QEAA@XZ)
> 1>node_inspector_agent.obj : error LNK2019: unresolved external symbol
> "public: static class std::unique_ptr v8_inspector::StringBuffer,struct std::default_delete v8_inspector::StringBuffer> > __cdecl
> v8_inspector::StringBuffer::create(class v8_inspector::StringView const &)"
> (?create@StringBuffer@v8_inspector@@SA?AV?$unique_ptr@VStringBuffer
> @v8_inspector@@U?$default_delete@VStringBuffer@v8_inspector@@@std@@@std@
> @AEBVStringView@2@@Z) referenced in function "class std::unique_ptr v8_inspector::StringBuffer,struct std::default_delete v8_inspector::StringBuffer> > __cdecl inspector::`anonymous
> namespace'::ToProtocolString(class v8::Isolate *,class v8::Local v8::Value>)" (?ToProtocolString@?A0xd3023fdb@inspector
> @@YA?AV?$unique_ptr@VStringBuffer@v8_inspector@
> @U?$default_delete@VStringBuffer@v8_inspector@@@std@@@std@@PEAVIsolate@v8
> @@V?$Local@VValue@v8@@@6@@Z)
> 1>node_inspector_io.obj : error LNK2001: unresolved external symbol
> "public: static class std::unique_ptr v8_inspector::StringBuffer,struct std::default_delete v8_inspector::StringBuffer> > __cdecl
> v8_inspector::StringBuffer::create(class v8_inspector::StringView const &)"
> (?create@StringBuffer@v8_inspector@@SA?AV?$unique_ptr@VStringBuffer
> @v8_inspector@@U?$default_delete@VStringBuffer@v8_inspector@@@std@@@std@
> @AEBVStringView@2@@Z)
> 1>node_inspector_agent.obj : error LNK2019: unresolved external symbol
> "public: static class std::unique_ptr v8_inspector::V8Inspector,struct std::default_delete v8_inspector::V8Inspector> > __cdecl
> v8_inspector::V8Inspector::create(class v8::Isolate *,class
> v8_inspector::V8InspectorClient *)" (?create@V8Inspector@v8_inspector@
> @SA?AV?$unique_ptr@VV8Inspector@v8_inspector@
> @U?$default_delete@VV8Inspector@v8_inspector@@@std@@@std@@PEAVIsolate@v8
> @@PEAVV8InspectorClient@2@@Z) referenced in function "public: __cdecl
> inspector::CBInspectorClient::CBInspectorClient(class v8::Isolate *,class
> v8::Platform *)" (??0CBInspectorClient@inspector@@QEAA@PEAVIsolate@v8@
> @PEAVPlatform@3@@Z)
> 1>v8_monolith.lib(bytecode-array-random-iterator.obj) : error LNK2001:
> unresolved external symbol "protected: void __cdecl
> std::__1::__vector_base_common<1>::__throw_length_error(void)const "
> (?__throw_length_error@?$__vector_base_common@$00@__1@std@@IEBAXXZ)
> 1>v8_monolith.lib(liftoff-assembler.obj) : error LNK2001: unresolved
> external symbol "protected: void __cdecl
> std::__1::__vector_base_common<1>::__throw_length_error(void)const "
> (?__throw_length_error@?$__vector_base_common@$00@__1@std@@IEBAXXZ)
> 1>v8_monolith.lib(constant-array-builder.obj) : error LNK2001: unresolved
> external symbol "protected: void __cdecl
> std::__1::__vector_base_common<1>::__throw_length_error(void)const "
> (?__throw_length_error@?$__vector_base_common@$00@__1@std@@IEBAXXZ)
> 1>v8_monolith.lib(bytecode-array-writer.obj) : error LNK2001: unresolved
> external symbol "protected: void __cdecl
> std::__1::__vector_base_common<1>::__throw_length_error(void)const "
> (?__throw_length_error@?$__vector_base_common@$00@__1@std@@IEBAXXZ)
>
>
>
> --
> --
> 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/22d72edc-a80c-436f-9b7b-d5da1f715fa2%40googlegroups.com
> 

Re: [v8-users] IsFunction() on v8::Name returns false

2019-09-26 Thread 'Simon Zünd' via v8-users
In terms of the JavaScript spec, you are performing a [[Set]] operation
with `dict[x] = x`. The key for [[Set]] must be a valid property key, which
is either a String or a Symbol. In this case, the code actually looks more
like `dict[x.toString()] = x`. This is just how JavaScript works, and is
intended.

On Thu, Sep 26, 2019 at 8:07 AM Gautham B A 
wrote:

> Hi all,
>
> Calling IsFunction() on v8::Local is returning false, even
> though v8::Local was pointing to a function in JavaScript. Is
> this expected? Consider the following code -
>
> #include 
> #include 
> #include 
> #include 
>
>
> void Getter(v8::Local key,
> const v8::PropertyCallbackInfo ) {
>   std::cout << "Getter:" << std::endl;
>   std::cout << "IsFunction: " << key->IsFunction() << std::endl;
> }
>
>
> void Setter(v8::Local key, v8::Local value,
> const v8::PropertyCallbackInfo ) {
>   std::cout << "Setter:" << std::endl;
>   // key->IsFunction() returns false, expected to be true
>   std::cout << "Key IsFunction: " << key->IsFunction() << std::endl;
>
>
>   // value->IsFunction() returns true, as expected
>   std::cout << "\nValue IsFunction:" << value->IsFunction() << std::endl;
> }
>
>
> void Deleter(v8::Local key,
>  const v8::PropertyCallbackInfo ) {}
>
>
> bool InstallMap(v8::Isolate *isolate, const v8::Local &
> context) {
>   v8::HandleScope handle_scope(isolate);
>   auto obj_template = v8::ObjectTemplate::New(isolate);
>   obj_template->SetHandler(
>   v8::NamedPropertyHandlerConfiguration(Getter, Setter, nullptr,
> Deleter));
>
>
>   v8::Local obj;
>   if (!obj_template->NewInstance(context).ToLocal()) {
> std::cerr << "Unable to instantiate object template" << std::endl;
> return false;
>   }
>
>
>   v8::Local obj_name;
>   if (!v8::String::NewFromUtf8(isolate, "dict", v8::String::kNormalString)
>->ToString(context)
>.ToLocal(_name)) {
> std::cerr << "Unable to create map key name" << std::endl;
> return false;
>   }
>
>
>   auto global = context->Global();
>   if (!global->Set(context, obj_name, obj).FromJust()) {
> std::cerr << "Unable to install object into global scope" << std::endl
> ;
> return false;
>   }
>   return true;
> }
>
>
> int main(int argc, char *argv[]) {
>   const auto script_str = R"(
>   function x() {
>   }
>
>
>   dict[x] = x;
>   )";
>
>
>   v8::V8::InitializeICUDefaultLocation(argv[0]);
>   v8::V8::InitializeExternalStartupData(argv[0]);
>   auto platform = v8::platform::NewDefaultPlatform();
>   v8::V8::InitializePlatform(platform.get());
>   v8::V8::Initialize();
>
>
>   v8::Isolate::CreateParams create_params;
>   create_params.array_buffer_allocator =
>   v8::ArrayBuffer::Allocator::NewDefaultAllocator();
>   v8::Isolate *isolate = v8::Isolate::New(create_params);
>   {
> v8::Isolate::Scope isolate_scope(isolate);
> v8::HandleScope handle_scope(isolate);
> auto context = v8::Context::New(isolate);
> v8::Context::Scope context_scope(context);
>
>
> InstallMap(isolate, context);
>
>
> auto source =
> v8::String::NewFromUtf8(isolate, script_str, v8::NewStringType::
> kNormal)
> .ToLocalChecked();
> auto script = v8::Script::Compile(context, source).ToLocalChecked();
> auto result = script->Run(context).ToLocalChecked();
> v8::String::Utf8Value result_utf8(isolate, result);
> std::cout << *result_utf8 << std::endl;
>   }
>   isolate->Dispose();
>   v8::V8::Dispose();
>   v8::V8::ShutdownPlatform();
>   delete create_params.array_buffer_allocator;
>   return 0;
> }
>
>
> As seen in the code above, I'm exposing a global variable dict which has
> the Setter, Getter and Deleter callbacks set appropriately on dict.
>
> function x() {
> }
> dict[x] = x;
> When I run the above JavaScript code, The Setter callback gets called and
> I see that *name* and *value* have different results upon calling
> IsFunction() on them.
> Could someone please tell me if this is the expected behavior, if so, the
> reason behind why it is so?
>
> Thanks,
> --Gautham
>
> --
> --
> 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/06da69ba-ec72-47d3-972d-7a241699b8fa%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 

Re: [v8-users] ArrayBuffer size is 0

2019-09-01 Thread 'Simon Zünd' via v8-users
Hey,

You are not accessing the "size" property, but treat "args[0]" as if it
were a number (which it is not, it's a ArrayBuffer). Since you have
established that args[0] is an ArrayBuffer, you can use cast, which would
look roughly like this:

Local array_buffer = Local::cast(args[0]);
size_t size = array_buffer->ByteLength();


On Mon, Sep 2, 2019 at 12:50 AM Jonathan Doster  wrote:

> Hey everyone!
>
> I am trying to pass an ArrayBuffer from JS to C++, and when I debug the
> "size" variable is 0.
> I do not understand what I am doing wrong, ultimately my goal is to be
> able to read and write the buffer, copy, etc.
> Thank you!!
>
> var api = require('../src/public/api')
> api.Method(new ArrayBuffer([1, 2, 3, 4]))
>
> void Method(const v8::FunctionCallbackInfo )
> {
> CHECK_ARGS(args, args[0]->IsArrayBuffer());
> uint32_t size = args[0]->Uint32Value();
> }
>
>
> --
> --
> 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/ed43b406-af94-49f1-94c2-47c09673379d%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/CACswSC1LA6dT66X12EOTNTrG29St8tnnHYp8uqhwARtid4ijcA%40mail.gmail.com.


Re: [v8-users] how to run v8 in debug mode so I can use the %DebugPrint

2019-08-16 Thread 'Simon Zünd' via v8-users
Yes, building V8 with {tools/dev/gm.py x64.debug} will configure a debug
build of V8. Please note that gm.py is just a convenience wrapper. The
source of truth for a build configuration can always be found in the {
args.gn} file of the respective build. In your case this should be
{out/x64.debug/args.gn}, which will contain a line {is_debug = true}.

On Fri, Aug 16, 2019 at 8:14 AM 杨亮  wrote:

> The doc says to build v8 with tools/dev/gm.py x64.release, so is that mean
> I should build the debug mode d8 with tools/dev/gm.py x64.debug ? Im not
> very shall how to build the v8 in debug mode. Very thanks man!
> On Friday, August 16, 2019 at 1:15:14 PM UTC+8, Rodolph Perfetta wrote:
>>
>> They probably meant you need to build d8 in debug mode. more info here:
>> https://v8.dev/docs/build
>>
>> On Thu, 15 Aug 2019 at 22:38, 杨亮  wrote:
>>
>>> Thanks man. In fact I have use the --allow-natives-syntax, but I can't
>>> get enough information about a function, someone say that I need run d8 In
>>> the debug mode, but I don't know how.
>>>
>>> On Thursday, August 15, 2019 at 10:38:07 PM UTC+8, Rodolph Perfetta
>>> wrote:

 To be able to use native functions starting with % such as %DebugPrint
 you need to pass --allow-natives-syntax to d8 on the command line.

 Cheers,
 Rodolph

 On Thu, 15 Aug 2019 at 09:26, 杨亮  wrote:

> hi,I want to know how I can run d8 in debug mode so I can
> use %DebugPrint command,I can just get one line output info,seems I need
> run d8 in the debug mode ?
>
> --
> --
> 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/1f274ea5-a181-443a-882b-a8249f247799%40googlegroups.com
> 
> .
>
 --
>>> --
>>> 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/5c6a92d3-3d7c-4101-84b3-387de584058f%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/10fc3bff-e340-458c-8235-b73de897b3cf%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/CACswSC0R%3DuAYauZ2-ZFiYSG%2BfEGM-QsbYVc6MhWNe624%2BpJRqw%40mail.gmail.com.


[v8-users] Re: [blink-dev] Intent to Remove: 'getThis' and 'getFunction' from the CallSite API

2019-07-03 Thread 'Simon Zünd' via v8-users
Use counters for 'getThis' and 'getFunction' have landed in 77.0.3829.0:

Blink.UseCounter.Features.V8CallSiteAPIGetFunctionSloppyCall
Blink.UseCounter.Features.V8CallSiteAPIGetThisSloppyCall

We will wait until 77 is promoted to stable and we get stable usage numbers
before making a final decision.

On Wed, Jul 3, 2019 at 8:44 AM Mathias Bynens  wrote:

> Non-Blink owner LGTM. As Simon points out, Error.prepareStackTrace is
> non-standard, and so I'm in favor of removing as much from it as we can.
>
> On Tue, Jul 2, 2019 at 6:15 PM 'Simon Zünd' via blink-dev <
> blink-...@chromium.org> wrote:
>
>> Contact emails szu...@chromium.org Summary A callback installed on the
>> non-standard Error.prepareStackTrace receives a list of CallSite objects.
>> These objects have various accessors on them, 'getThis' and 'getFunction'
>> among them. In-depth information:
>> https://v8.dev/docs/stack-trace-api#customizing-stack-traces
>>
>> These two functions are rarely used and complicate the stack trace
>> implementation.
>> Will this feature be supported on all six Blink platforms (Windows, Mac,
>> Linux, Chrome OS, Android, and Android WebView)? Yes Is this feature
>> fully tested by web-platform-tests
>> 
>> ? No Link to entry on the Chrome Platform Status
>> https://chromestatus.com/feature/5975936472186880
>> This intent message was generated by Chrome Platform Status
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "blink-dev" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to blink-dev+unsubscr...@chromium.org.
>> To view this discussion on the web visit
>> https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CACswSC14TCiY%2BTA6PNPP1HEpR3tJMw24pCxG81Ta1CjL9%3DapqQ%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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CACswSC2FYhsHvfDtxeZPfOoeJxScJySJPLZAQ8SMWpTxNfceAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.