Created
February 2, 2011 17:34
-
-
Save mraleph/808039 to your computer and use it in GitHub Desktop.
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
v8::Local<v8::Function> MkFunction(v8::Handle<v8::String> body) { | |
v8::HandleScope scope; | |
// Get global object | |
v8::Local<v8::Object> global = v8::Context::GetCurrent()->Global(); | |
// Get built-in Function constructor (see ECMA-262 5th edition 15.3.2) | |
v8::Local<v8::Function> function_ctor = | |
v8::Local<v8::Function>::Cast(global->Get(v8::String::New("Function"))); | |
// Invoke Function constructor to create function with the given body and no arguments | |
v8::Handle<v8::Value> argv[1] = { body }; | |
v8::Local<v8::Object> function = function_ctor->NewInstance(1, argv); | |
return scope.Close(v8::Local<v8::Function>::Cast(function)); | |
} |
I hope there is no sarcasm in your words as I tried to make it as readable as possible --- this is an answer to a question of a V8 embedder :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Readability masterpiece. =)