Hi All,
We are trying to replace a component (of our current product) with V8
engine. I am writing a V8 helper class in C++.
Init(): to initialize V8 engine and compile the given JavaScript.
Run(): to run the compiled script.
The Run() will be called more than 100,000,000 times. Could you give us
some suggestions to optimize this part?
Thank you very much!!
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Persistent<Context, CopyablePersistentTraits<Context>> _context;
Persistent<Script, CopyablePersistentTraits<Script>> _script;
void Init(char *strJavaScript)
{
strScript = strJavaScript;
this->isolate = Isolate::New();
isolate->Enter();
Isolate::Scope isolate_scope(this->isolate);
HandleScope handle_scope(this->isolate);
Handle<ObjectTemplate> templ = ObjectTemplate::New(this->isolate);
templ->SetAccessor(v8_str("inputStr"), getStringValue, setStringValue,
External::New(this->isolate, &inputStr));
templ->SetAccessor(v8_str("inputNum"), getIntValue, setIntValue,
External::New(this->isolate, &inputNum));
templ->SetAccessor(v8_str("outputStr"), getStringValue, setStringValue,
External::New(this->isolate, &outputStr));
templ->SetAccessor(v8_str("outputNum"), getIntValue, setIntValue,
External::New(this->isolate, &outputNum));
Handle<Context> context = Context::New(isolate, NULL, templ);
_context = Persistent<Context, CopyablePersistentTraits<Context>>(isolate,
context);
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::NewFromUtf8(isolate, strScript);
// Compile the given JavaScript
Handle<Script> script = Script::Compile(source);
_script = Persistent<Script, CopyablePersistentTraits<Script>>(isolate,
script);
}
void Run()
{
HandleScope scope(Isolate::GetCurrent());
Context::Scope context_scope(Local<Context>::New(Isolate::GetCurrent(),
this->_context));
*Local<Value> result = Local<Script>::New(Isolate::GetCurrent(),
this->_script)->Run();*
}
--
--
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.