Created
October 21, 2015 22:16
-
-
Save goldsborough/1b538c08dbb1ee74a908 to your computer and use it in GitHub Desktop.
Include a JavaScript file in Google V8.
This file contains hidden or 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
void include(const v8::FunctionCallbackInfo<v8::Value>& file) | |
{ | |
auto isolate = file.GetIsolate(); | |
if (file.Length() != 1) | |
{ | |
auto message = v8::String::NewFromUtf8(isolate, | |
"Invalid number " | |
"of arguments!"); | |
v8::Exception::SyntaxError(message); | |
} | |
std::ifstream stream(*v8::String::Utf8Value(file[0])); | |
std::string source; | |
std::string input; | |
while (std::getline(stream, input)) | |
{ | |
source += input + "\n"; | |
} | |
auto string = v8::String::NewFromUtf8(isolate, source.c_str()); | |
auto script = v8::Script::Compile(string); | |
script->Run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment