// Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. #include "node.h" #include "node_script.h" #include "node_watchdog.h" #include namespace node { using v8::Context; using v8::Script; using v8::Value; using v8::Handle; using v8::HandleScope; using v8::Object; using v8::Arguments; using v8::ThrowException; using v8::TryCatch; using v8::String; using v8::Exception; using v8::Local; using v8::Array; using v8::Persistent; using v8::Integer; using v8::Function; using v8::FunctionTemplate; using v8::V8; class WrappedContext : ObjectWrap { public: static void Initialize(Handle target); static Handle New(const Arguments& args); Persistent GetV8Context(); static Local NewInstance(); static bool InstanceOf(Handle value); protected: static Persistent constructor_template; WrappedContext(); ~WrappedContext(); Persistent context_; }; Persistent WrappedContext::constructor_template; class WrappedScript : ObjectWrap { public: static void Initialize(Handle target); enum EvalInputFlags { compileCode, unwrapExternal }; enum EvalContextFlags { thisContext, newContext, userContext }; enum EvalOutputFlags { returnResult, wrapExternal }; enum EvalTimeoutFlags { noTimeout, useTimeout }; template static Handle EvalMachine(const Arguments& args); protected: static Persistent constructor_template; WrappedScript() : ObjectWrap() {} ~WrappedScript(); static Handle New(const Arguments& args); static Handle CreateContext(const Arguments& arg); static Handle RunInContext(const Arguments& args); static Handle RunInThisContext(const Arguments& args); static Handle RunInNewContext(const Arguments& args); static Handle CompileRunInContext(const Arguments& args); static Handle CompileRunInThisContext(const Arguments& args); static Handle CompileRunInNewContext(const Arguments& args); Persistent