Forked from ghaiklor/v8-compile-javascript-example.cc
Created
October 12, 2019 11:27
-
-
Save deepal/ed11aef6f94d09da5747b40060ead19f to your computer and use it in GitHub Desktop.
Simple example how V8 can compile JavaScript source and run it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new context. | |
Local<Context> context = Context::New(isolate); | |
// Enter the context for compiling and running the hello world script. | |
Context::Scope context_scope(context); | |
// Create a string containing the JavaScript source code. | |
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
// Compile the source code. | |
Local<Script> script = Script::Compile(source); | |
// Run the script to get the result. | |
Local<Value> result = script->Run(); | |
// Convert the result to an UTF8 string and print it. | |
String::Utf8Value utf8(result); | |
printf("%s\n", *utf8); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment