Hi there,
I'm using a V8 checkout from the 22nd of October 2016.
My approach is probably wrong in some way, but the following is what I try
to achieve.
Compiling and running a script that defines an ES6 class "some_class"... my
wish is being able to make instances of this class in C++.
I *think* I have to get some kind of handle to "some_class" first, then do
a NewInstance() on it (or something), but I already get stuck in the first
part, getting "some_class" from the context.
For example, I have this code:
std::string some_js(R"(
function foo() {
//impl
}
class some_class {
constructor() {
//impl
}
};
)");
// Compile and run above script
Local<String> source = String::NewFromUtf8(isolate, some_js.c_str(),
NewStringType::kNormal).ToLocalChecked();
Local<Script> script = Script::Compile(context, source).ToLocalChecked();
Local<Value> result = script->Run(context).ToLocalChecked();
I can then successfully get the function "foo" from it like this:
Local<String> foo = String::NewFromUtf8(isolate, "foo",
NewStringType::kNormal).ToLocalChecked();
Handle<Value> value_foo = context->Global()->Get(foo);
// At this point: value_foo->IsFunction() == true
However, then my attempt to get the class the same way:
Local<String> some_class = String::NewFromUtf8(isolate, "some_class",
NewStringType::kNormal).ToLocalChecked();
Handle<Value> value_some_class = context->Global()->Get(some_class);
// At this point: value_some_class->IsUndefined() == true
So it yields 'undefined', I expected at least something.. I found some code
where new instances were created grepping the V8 tests, but as far as I can
tell they all construct an object from scratch,
where I wish to use an existing user defined class.
I have a full test case here:
https://gist.github.com/rayburgemeestre/df6193d532c7b7908fe27c89799bfa3a
Any help pointing me in the right direction would be very appreciated!
Kind regards,
Ray Burgemeestre
--
--
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.