diff --git a/include/OSS/JS/JS.h b/include/OSS/JS/JS.h index b64f457377..cdd989c9d8 100644 --- a/include/OSS/JS/JS.h +++ b/include/OSS/JS/JS.h @@ -27,270 +27,340 @@ #define OSS_JS_BUILD_NUMBER 0 - +#include #include "OSS/OSS.h" #include #include "OSS/JS/JSObjectWrap.h" -#define CONST_EXPORT(Name) exports->Set(v8::String::New(#Name), v8::Integer::New(Name), v8::ReadOnly); -#define TYPE_ERROR_EXCEPTION(Msg) v8::Exception::TypeError(v8::String::NewSymbol(Msg)); - +#define js_get_v8_isolate() v8::Isolate::GetCurrent() +#define js_get_v8_context() js_get_v8_isolate()->GetCurrentContext() +#define js_get_v8_global() js_get_v8_context()->Global() +//#define js_get_v8_global() OSS::JS::JSIsolateManager::instance().getIsolate()->getGlobal() +// Type Definitions // -// Class and method implementation macros -// -#define JS_CONSTRUCTOR_DECLARE() \ - static JSPersistentFunctionHandle _constructor; \ - static void Init(JSObjectHandle exports); \ - static v8::Handle New(const v8::Arguments& _args_); - -typedef v8::Handle (*JS_METHOD_FUNC)(const v8::Arguments&); - -#define JS_METHOD_DECLARE(Method) static v8::Handle Method(const v8::Arguments& _args_) -#define JS_INDEX_GETTER_DECLARE(Method) static v8::Handle Method(uint32_t index, const v8::AccessorInfo& _args_); -#define JS_INDEX_SETTER_DECLARE(Method) static v8::Handle Method(uint32_t index, v8::Local value, const v8::AccessorInfo& _args_); - -#define js_export_method(Name, Func) exports->Set(v8::String::NewSymbol(Name), v8::FunctionTemplate::New(Func)->GetFunction()) -#define js_export_global_constructor(Name, Func) js_get_global()->Set(v8::String::NewSymbol(Name), Func) -#define js_export_const CONST_EXPORT -#define js_export_string(Name, Value) exports->Set(v8::String::NewSymbol(Name), v8::String::NewSymbol(Value), v8::ReadOnly) -#define js_export_string_symbol(Name) exports->Set(v8::String::NewSymbol(Name), v8::String::NewSymbol(Name), v8::ReadOnly) -#define js_export_int32(Name, Value) exports->Set(v8::String::NewSymbol(Name), v8::Int32::New(Value), v8::ReadOnly) - -#define JS_CLASS_INTERFACE(Class, Name) \ - JSPersistentFunctionHandle Class::_constructor; \ - void Class::Init(v8::Handle exports) {\ - js_enter_scope(); \ - std::string className = Name; \ - v8::Local tpl = OSS::JS::JSObjectWrap::ExportConstructorTemplate(Name, exports); - -#define JS_CLASS_METHOD_DEFINE(Class, Name, Func) OSS::JS::JSObjectWrap::ExportMethod(tpl, Name, Func) - -#define JS_CLASS_INDEX_ACCESSOR_DEFINE(Class, Getter, Setter) OSS::JS::JSObjectWrap::ExportIndexHandler(tpl, Getter, Setter); -#define JS_CLASS_INTERFACE_END(Class) } OSS::JS::JSObjectWrap::FinalizeConstructorTemplate(className.c_str(), tpl, exports); -#define js_export_class(Class) Class::Init(exports) - -#define JS_METHOD_IMPL(Method) v8::Handle Method(const v8::Arguments& _args_)\ - -#define JS_CONSTRUCTOR_IMPL(Class) JS_METHOD_IMPL(Class::New) - -#define JS_INDEX_GETTER_IMPL(Method) JSValueHandle Method(uint32_t index, const v8::AccessorInfo& _args_) - -#define JS_INDEX_SETTER_IMPL(Method) JSValueHandle Method(uint32_t index,v8::Local value, const v8::AccessorInfo& _args_) - -#define JS_EXPORTS_INIT() static v8::Handle init_exports(const v8::Arguments& _args_) { \ - v8::Local exports = v8::Local::New(v8::Object::New()); - -#define js_export_finalize() } return exports; - -// -// Value Definitions -// -#define JSUndefined() v8::Undefined() -#define JSValueHandle v8::Handle +#define JSAccessorInfo const v8::PropertyCallbackInfo& +#define JSSetAccessorInfo const v8::PropertyCallbackInfo& +#define JSCallbackInfo const v8::FunctionCallbackInfo& +#define JSValueHandle v8::Local #define JSLocalValueHandle v8::Local -#define JSStringHandle v8::Handle +#define JSMaybeLocalValueHandle v8::MaybeLocal +#define JSUndefinedHandle v8::Local +#define JSStringHandle v8::Local +#define JSBooleanHandle v8::Local +#define JSIntegerHandle v8::Local #define JSLocalStringHandle v8::Local #define JSArrayHandle v8::Handle #define JSLocalArrayHandle v8::Local -#define JSObjectHandle v8::Handle -#define JSObjectTemplateHandle v8::Handle +#define JSContextHandle v8::Local +#define JSObjectHandle v8::Local +#define JSExternalHandle v8::Local +#define JSObjectTemplateHandle v8::Local #define JSLocalObjectHandle v8::Local #define JSLocalObjectTemplateHandle v8::Local -#define JSLocalObjectTemplateHandle v8::Local +#define JSPersistentValueHandle v8::Persistent +#define JSCopyablePersistentValueHandle v8::Persistent> #define JSPersistentObjectHandle v8::Persistent -#define JSLiteral(Text) v8::String::NewSymbol(Text) -#define JSExternalHandle v8::Handle +#define JSPersistentObjectTemplateHandle v8::Persistent +#define JSCopyablePersistentObjectTemplateHandle v8::Persistent> +#define JSPersistentContextHandle v8::Persistent +#define JSCopyablePersistentContextHandle v8::Persistent> +#define JSExternalHandle v8::Local #define JSPersistentFunctionHandle v8::Persistent -#define JSFunctionHandle v8::Handle +#define JSCopyablePersistentFunctionHandle v8::Persistent> +#define JSPersistentFunctionTemplateHandle v8::Persistent +#define JSFunctionTemplateHandle v8::Local +#define JSFunctionHandle v8::Local #define JSLocalFunctionHandle v8::Local -#define JSPersistentFunctionCast(Handle) JSPersistentFunctionHandle::New(JSFunctionHandle::Cast(Handle)) -inline JSStringHandle JSString(const char* str) { return v8::String::New(str); } -inline JSStringHandle JSString(const std::string& str) { return v8::String::New(str.data(), str.size()); } -inline JSStringHandle JSString(const char* str, std::size_t len) { return v8::String::New(str, len); } - -#define JSArguments const v8::Arguments -#define JSArgumentVector std::vector< v8::Handle > +#define JSArgumentVector std::vector< v8::Local > #define JSLocalArgumentVector std::vector< v8::Local > #define JSPersistentArgumentVector std::vector< v8::Persistent > -#define JSBoolean(Exp) v8::Boolean::New(Exp) -#define JSArray(Size) v8::Array::New(Size) -#define JSInt32(Value) v8::Int32::New(Value) -#define JSUInt32(Value) v8::Uint32::New(Value) -#define JSInteger(Value) v8::Integer::New(Value) -#define JSObject() v8::Object::New() -#define JSObjectTemplate() v8::ObjectTemplate::New() -#define JSStringNew(Str) v8::String::New(Str) -#define JSExternal(Ptr) v8::External::New(Ptr) -#define JSException(What) v8::ThrowException(v8::Exception::Error(JSLiteral(What))) - -#define JSFalse JSBoolean(false) -#define JSTrue JSBoolean(true) - - +#define JSCopyablePersistentArgumentVector std::vector< v8::Persistent> > // // Helper functions // -#define js_throw(What) return JSException(What) -#define js_assert(Expression, What) if (!(Expression)) { js_throw(What); } -#define js_is_function(Handle) Handle->IsFunction() -#define js_get_global() OSS::JS::JSIsolateManager::instance().getIsolate()->getGlobal() -#define js_get_global_method(Name) js_get_global()->Get(JSLiteral(Name)) -#define js_enter_scope() v8::HandleScope _scope_ -#define js_unwrap_object(Class, Object) OSS::JS::JSObjectWrap::Unwrap(Object) +//#define js_throw(what) JSException(what) +//#define js_assert(Expression, what) if (!(Expression)) { js_throw(what); } +//#define js_is_function(handle) handle->IsFunction() +//#define js_get_global_method(name) js_get_v8_global()->Get(JSString(name)) +//#define js_enter_scope(isolate) v8::HandleScope _scope_(isolate) +//#define js_method_try_catch() v8::TryCatch _try_catch_(js_get_v8_isolate()); +#define js_unwrap_object(class, object) OSS::JS::JSObjectWrap::Unwrap(object) + +inline JSStringHandle JSString(v8::Isolate* isolate, const char* str) { return v8::String::NewFromUtf8(isolate,str).ToLocalChecked(); } +//inline JSStringHandle JSString(const char* str) { return JSString(js_get_v8_isolate(),str); } +inline JSStringHandle JSString(v8::Isolate* isolate, const std::string& str) { return v8::String::NewFromUtf8(isolate, str.data(), v8::NewStringType::kNormal ).ToLocalChecked(); } +//inline JSStringHandle JSString(const std::string& str) { return JSString(js_get_v8_isolate(),str); } +inline JSStringHandle JSString(v8::Isolate* isolate, const char* str, std::size_t len) { return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal, len).ToLocalChecked(); } +//inline JSStringHandle JSString(const char* str, std::size_t len) { return JSString(js_get_v8_isolate(), str, len); } +inline JSBooleanHandle JSBoolean(v8::Isolate* isolate, bool exp) { return v8::Boolean::New(isolate,exp); } +//inline JSBooleanHandle JSBoolean( bool exp) { return v8::Boolean::New(js_get_v8_isolate(),exp); } +inline JSArrayHandle JSArray(v8::Isolate* isolate, int size) { return v8::Array::New(isolate,size); } +//inline JSArrayHandle JSArray(int size) { return v8::Array::New(js_get_v8_isolate(),size); } +inline JSIntegerHandle JSInt32(v8::Isolate* isolate, int32_t value) { return v8::Int32::New(isolate,value); } +//inline JSIntegerHandle JSInt32(int32_t value) { return v8::Int32::New(js_get_v8_isolate(),value); } +inline JSIntegerHandle JSUint32(v8::Isolate* isolate, uint32_t value) { return v8::Uint32::NewFromUnsigned(isolate,value); } +//inline JSIntegerHandle JSUint32(uint32_t value) { return v8::Uint32::NewFromUnsigned(js_get_v8_isolate(),value); } +inline JSIntegerHandle JSInteger(v8::Isolate* isolate, int value) { return v8::Integer::New(isolate,value); } +//inline JSIntegerHandle JSInteger( int value) { return v8::Integer::New(js_get_v8_isolate(),value); } +inline JSObjectHandle JSObject(v8::Isolate* isolate) { return v8::Object::New(isolate); } +//inline JSObjectHandle JSObject() { return v8::Object::New(js_get_v8_isolate()); } +inline JSObjectTemplateHandle JSObjectTemplate(v8::Isolate* isolate) { return v8::ObjectTemplate::New(isolate); } +//inline JSObjectTemplateHandle JSObjectTemplate() { return v8::ObjectTemplate::New(js_get_v8_isolate()); } +inline JSExternalHandle JSExternal(v8::Isolate* isolate, void* ptr) { return v8::External::New(isolate,ptr); } +//inline JSExternalHandle JSExternal(void* ptr) { return v8::External::New(js_get_v8_isolate(),ptr); } +inline JSUndefinedHandle JSUndefined(v8::Isolate* isolate) { return v8::Undefined(isolate); } +//inline JSUndefinedHandle JSUndefined() { return v8::Undefined(js_get_v8_isolate()); } +inline JSFunctionTemplateHandle JSFunctionTemplate(v8::Isolate* isolate,v8::FunctionCallback callback) { return v8::FunctionTemplate::New(isolate,callback); } +//inline JSFunctionTemplateHandle JSFunctionTemplate(v8::FunctionCallback callback) { return v8::FunctionTemplate::New(js_get_v8_isolate(),callback); } + +inline void JSException(v8::Isolate* isolate, const char* what) { isolate->ThrowException(v8::Exception::Error(JSString(isolate,what))); } +inline void JSException(v8::Isolate* isolate, std::string what) { isolate->ThrowException(v8::Exception::Error(JSString(isolate,what))); } +//inline void JSException(const char* what) { js_get_v8_isolate()->ThrowException(v8::Exception::Error(JSString(what))); } +//inline void JSException(std::string what) { js_get_v8_isolate()->ThrowException(v8::Exception::Error(JSString(what))); } // -// Argument parsing +// Class and method implementation macros // -#define js_method_arg_self() _args_.This() -#define js_method_arg_length() _args_.Length() -#define js_method_arg(Index) _args_[Index] - -#define js_method_arg_is_object(Index) _args_[Index]->IsObject() -#define js_method_arg_is_string(Index) _args_[Index]->IsString() -#define js_method_arg_is_array(Index) _args_[Index]->IsArray() -#define js_method_arg_is_number(Index) _args_[Index]->IsNumber() -#define js_method_arg_is_int32(Index) _args_[Index]->IsInt32() -#define js_method_arg_is_uint32(Index) _args_[Index]->IsUint32() -#define js_method_arg_is_bool(Index) _args_[Index]->IsBoolean() -#define js_method_arg_is_date(Index) _args_[Index]->IsDate() -#define js_method_arg_is_buffer(Index) BufferObject::isBuffer(_args_[Index]) -#define js_method_arg_is_function(Index) _args_[Index]->IsFunction() - -#define js_method_arg_assert_size_eq(Value) if (_args_.Length() != Value) js_throw("Invalid Argument Count") -#define js_method_arg_assert_size_gt(Value) if (_args_.Length() <= Value) js_throw("Invalid Argument Count") -#define js_method_arg_assert_size_lt(Value) if (_args_.Length() >= Value) js_throw("Invalid Argument Count") -#define js_method_arg_assert_size_gteq(Value) if (_args_.Length() < Value) js_throw("Invalid Argument Count") -#define js_method_arg_assert_size_lteq(Value) if (_args_.Length() > Value) js_throw("Invalid Argument Count") -#define js_method_arg_assert_object(Index) if (!js_method_arg_is_object(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_string(Index) if (!js_method_arg_is_string(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_array(Index) if (!js_method_arg_is_array(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_number(Index) if (!js_method_arg_is_number(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_int32(Index) if (!js_method_arg_is_int32(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_uint32(Index) if (!js_method_arg_is_uint32(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_bool(Index) if (!js_method_arg_is_bool(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_date(Index) if (!js_method_arg_is_date(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_buffer(Index) if (!js_method_arg_is_buffer(Index)) js_throw("Invalid Argument Type") -#define js_method_arg_assert_function(Index) if (!js_method_arg_is_function(Index)) js_throw("Invalid Argument Type") - -#define js_method_arg_as_object(Index) _args_[Index]->ToObject() -#define js_method_arg_as_string(Index) v8::String::Utf8Value(_args_[Index]) -#define js_method_arg_as_std_string(Index) std::string((const char*) *js_method_arg_as_string(Index)) -#define js_method_arg_as_array(Index) JSArrayHandle::Cast(_args_[Index]) -#define js_method_arg_as_integer(Index) _args_[Index]->IntegerValue() -#define js_method_arg_as_number(Index) _args_[Index]->NumberValue() -#define js_method_arg_as_int32(Index) _args_[Index]->Int32Value() -#define js_method_arg_as_uint32(Index) _args_[Index]->Uint32Value() -#define js_method_arg_as_bool(Index) _args_[Index]->BooleanValue() -#define js_method_arg_as_buffer(Index) js_method_arg_unwrap_object(BufferObject, Index) -#define js_method_arg_as_persistent_function(Index) v8::Persistent::New(v8::Handle::Cast(_args_[Index])) - -#define js_method_arg_has_property(Index, Name) _args_[Index]->ToObject()->Has(v8::String::NewSymbol(Name)) -#define js_method_arg_get_property(Index, Name) _args_[Index]->ToObject()->Get(v8::String::NewSymbol(Name)) - -#define js_method_arg_unwrap_object(Class, Index) js_unwrap_object(Class, js_method_arg_as_object(Index)) -#define js_method_arg_unwrap_self(Class) js_unwrap_object(Class, js_method_arg_self()) - -#define js_setter_info_unwrap_self js_method_arg_unwrap_self -#define js_getter_info_unwrap_self js_method_arg_unwrap_self -#define js_setter_value_as_uint32() value->ToUint32()->Value() + + +#define JS_GLOBAL_FUNCTION_DECLARE(global) void global(JSCallbackInfo _args_) +#define JS_GLOBAL_FUNCTION_IMPL(function) void function(JSCallbackInfo _args_) + +#define JS_METHOD_DECLARE(method) static void method(JSCallbackInfo _args_) +#define JS_METHOD_IMPL(method) void method(JSCallbackInfo _args_) + +#define JS_INDEX_GETTER_DECLARE(method) static void method(uint32_t index, JSAccessorInfo _args_); +#define JS_INDEX_GETTER_IMPL(method) void method(uint32_t index, JSAccessorInfo _args_) + +#define JS_INDEX_SETTER_DECLARE(method) static void method(uint32_t index, v8::Local value, JSAccessorInfo _args_); +#define JS_INDEX_SETTER_IMPL(method) void method(uint32_t index,v8::Local value, JSAccessorInfo _args_) + +#define JS_ACCESSOR_GETTER_DECLARE(method) static void method(v8::Local property, JSAccessorInfo _args_); +#define JS_ACCESSOR_GETTER_IMPL(method) void method(v8::Local property, JSAccessorInfo _args_) + +#define JS_ACCESSOR_SETTER_DECLARE(method) static void method(v8::Local property, v8::Local value, JSSetAccessorInfo _args_); +#define JS_ACCESSOR_SETTER_IMPL(method) void method(v8::Local property, v8::Local value, JSSetAccessorInfo _args_) + +#define JS_CONSTRUCTOR_DECLARE() \ + static JSCopyablePersistentFunctionHandle _constructor; \ + static void Init(v8::Isolate* isolate, JSObjectHandle exports); \ + static void New(JSCallbackInfo _args_); + +#define JS_CONSTRUCTOR_IMPL(class) JS_METHOD_IMPL(class::New) + +#define js_method_self() _args_.This() +#define js_method_args_length() _args_.Length() +#define js_method_arg(index) _args_[index] +#define js_method_isolate() _args_.GetIsolate() +#define js_method_context() js_method_isolate()->GetCurrentContext() +#define js_method_global() js_method_context()->Global() + +#define js_method_string(value) JSString(js_method_isolate(),value) +#define js_method_boolean(value) JSBoolean(js_method_isolate(),value) +#define js_method_array(size) JSArray(js_method_isolate(),size) +#define js_method_int32(value) JSInt32(js_method_isolate(),value) +#define js_method_uint32(value) JSUint32(js_method_isolate(),value) +#define js_method_integer(value) JSInteger(js_method_isolate(),value) +#define js_method_object() JSObject(js_method_isolate()) +#define js_method_object_template() JSObjectTemplate(js_method_isolate()) +#define js_method_external(ptr) JSExternal(js_method_isolate(),ptr) +#define js_method_undefined() JSUndefined(js_method_isolate()) +#define js_method_function_template(callback) JSFunctionTemplate(js_method_isolate(),callback) + +#define js_method_try_catch() v8::TryCatch _try_catch_(js_method_isolate()); +#define js_method_exception(what) JSException(js_method_isolate(),what) + +#define js_method_arg_is_object(index) _args_[index]->IsObject() +#define js_method_arg_is_string(index) _args_[index]->IsString() +#define js_method_arg_is_array(index) _args_[index]->IsArray() +#define js_method_arg_is_number(index) _args_[index]->IsNumber() +#define js_method_arg_is_int32(index) _args_[index]->IsInt32() +#define js_method_arg_is_uint32(index) _args_[index]->IsUint32() +#define js_method_arg_is_bool(index) _args_[index]->IsBoolean() +#define js_method_arg_is_date(index) _args_[index]->IsDate() +#define js_method_arg_is_buffer(index) BufferObject::isBuffer(js_method_isolate(),_args_[index]) +#define js_method_arg_is_function(index) _args_[index]->IsFunction() + +#define js_method_args_assert_size_eq(value) if (_args_.Length() != value) js_method_throw("Invalid Argument Count") +#define js_method_args_assert_size_gt(value) if (_args_.Length() <= value) js_method_throw("Invalid Argument Count") +#define js_method_args_assert_size_lt(value) if (_args_.Length() >= value) js_method_throw("Invalid Argument Count") +#define js_method_args_assert_size_gteq(value) if (_args_.Length() < value) js_method_throw("Invalid Argument Count") +#define js_method_args_assert_size_lteq(value) if (_args_.Length() > value) js_method_throw("Invalid Argument Count") +#define js_method_arg_assert_object(index) if (!js_method_arg_is_object(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_string(index) if (!js_method_arg_is_string(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_array(index) if (!js_method_arg_is_array(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_number(index) if (!js_method_arg_is_number(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_int32(index) if (!js_method_arg_is_int32(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_uint32(index) if (!js_method_arg_is_uint32(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_bool(index) if (!js_method_arg_is_bool(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_date(index) if (!js_method_arg_is_date(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_buffer(index) if (!js_method_arg_is_buffer(index)) js_method_throw("Invalid Argument Type") +#define js_method_arg_assert_function(index) if (!js_method_arg_is_function(index)) js_method_throw("Invalid Argument Type") + +#define js_method_arg_as_object(index) _args_[index]->ToObject(js_method_context()).ToLocalChecked() +#define js_method_arg_as_string(index) v8::String::Utf8Value(js_method_isolate(),_args_[index]) +#define js_method_arg_as_std_string(index) std::string((const char*) *js_method_arg_as_string(index)) +#define js_method_arg_as_array(index) JSArrayHandle::Cast(_args_[index]) +#define js_method_arg_as_integer(index) _args_[index]->IntegerValue(js_method_context()).ToChecked() +#define js_method_arg_as_number(index) _args_[index]->NumberValue(js_method_context()).ToChecked() +#define js_method_arg_as_int32(index) _args_[index]->Int32Value(js_method_context()).ToChecked() +#define js_method_arg_as_uint32(index) _args_[index]->Uint32Value(js_method_context()).ToChecked() +#define js_method_arg_as_bool(index) _args_[index]->BooleanValue(js_method_isolate()) + +#define js_method_unwrap_object(class, index) js_unwrap_object(class, js_method_arg_as_object(index)) +#define js_method_unwrap_self(class) js_unwrap_object(class, js_method_self()) + +#define js_method_arg_as_buffer(index) js_method_unwrap_object(BufferObject, index) +#define js_method_arg_as_persistent_function(index) JSCopyablePersistentFunctionHandle(js_method_isolate(),v8::Handle::Cast(_args_[index])) + +#define js_method_enter_scope() v8::HandleScope _scope_(js_method_isolate()) +#define js_method_throw(what) js_method_exception(what) +#define js_method_assert(expression, what) if (!(expression)) { js_method_throw(what); } + +#define js_setter_info_unwrap_self js_method_unwrap_self +#define js_getter_info_unwrap_self js_method_unwrap_self +#define js_setter_value_as_uint32() value->Uint32Value(js_method_context()).ToChecked() #define js_setter_index() index #define js_getter_index js_setter_index -#define js_handle_as_string(Handle) v8::String::Utf8Value(Handle) -#define js_handle_as_std_string(Handle) std::string((const char*) *js_handle_as_string(Handle)) +#define js_method_handle_as_string(handle) v8::String::Utf8Value(js_method_isolate(),handle) +#define js_method_handle_as_std_string(handle) std::string((const char*) *js_method_handle_as_string(handle)) + +#define js_method_type(type, var, index, func, msg) \ + type var(0); \ + if (index >= _args_.Length()) \ + js_method_throw("Invalid Argument Count"); \ + if (!func(_args_, var, _args_[index])) \ + js_method_throw(msg); + +#define js_method_instance(class, instance, index, func, msg) \ + class instance; \ + if (index >= _args_.Length()) \ + js_method_throw("Invalid Argument Count"); \ + if (!func(_args_, instance, _args_[index])) \ + js_method_throw(msg); + +#define js_method_declare_bool(var, index) js_method_type(bool, var, index, js_method_assign_bool, "Invalid Type. Expecting Bool") +#define js_method_declare_uint32(var, index) js_method_type(uint32_t, var, index, js_method_assign_uint32, "Invalid Type. Expecting UInt32") +#define js_method_declare_int32(var, index) js_method_type(int32_t, var, index, js_method_assign_int32, "Invalid Type. Expecting Int32") +#define js_method_declare_number(var, index) js_method_type(double, var, index, js_method_assign_number, "Invalid Type. Expecting Nymber") +#define js_method_declare_string(var, index) js_method_type(std::string, var, index, js_method_assign_string, "Invalid Type. Expecting String") +#define js_method_declare_array(var, index) js_method_instance(JSArrayHandle, var, index, js_method_assign_array, "Invalid Class. Expecting Array") +#define js_method_declare_object(var, index) js_method_instance(JSObjectHandle, var, index, js_method_assign_object, "Invalid Class. Expecting Object") +#define js_method_declare_unwrapped_object(class, var, index) js_method_declare_object(_##var##__temp, index); class* var = js_unwrap_object(class, _##var##__temp->ToObject()) +#define js_method_declare_external_object(class, var, index) js_method_type(class*, var, index, js_method_assign_external_object, "Invalid Class. Expecting External Object") +#define js_method_declare_function(var, index) js_method_instance(JSLocalFunctionHandle, var, index, js_method_assign_function, "Invalid Type. Expecting Function") +#define js_method_declare_persistent_function(var, index) js_method_instance(JSPersistentFunctionHandle, var, index, js_method_assign_persistent_function, "Invalid Class. Expecting Function") +#define js_method_declare_copyable_persistent_function(var, index) js_method_instance(JSCopyablePersistentFunctionHandle, var, index, js_method_assign_persistent_function, "Invalid Class. Expecting Function") +#define js_method_declare_self(class, var) class* var = js_method_unwrap_self(class) + +#define js_method_declare_isolate(var) OSS::JS::JSIsolate::Ptr var = OSS::JS::JSIsolateManager::instance().getIsolate(); \ + if (!var) { js_method_throw("Unable to retrieve isolate"); } + +#define js_export_method(name, method) exports->Set(js_method_context(),js_method_string(name), v8::FunctionTemplate::New(js_method_isolate(),method)->GetFunction(js_method_context()).ToLocalChecked()) +#define js_export_global_constructor(name, method) js_method_global()->Set(js_method_context(), js_method_string(name), method) +#define js_export_value(name, value) exports->Set(js_method_context(), js_method_string(name), value) +#define js_export_const(name) exports->Set( js_method_context(), js_method_string(#name), js_method_integer(name)); +#define js_export_string(name, value) exports->Set(js_method_context(), js_method_string(name), js_method_string(value)) +#define js_export_string_symbol(name) exports->Set(js_method_context(), js_method_string(name), js_method_string(name)) +#define js_export_int32(name, value) exports->Set(js_method_context(), js_method_string(name), js_method_int32(value)) +#define js_export_uint32(name, value) exports->Set(js_method_context(), js_method_string(name), js_method_uint32(value)) +#define js_export_accessor(name, getFunc, setFunc) js_method_global()->SetAccessor(js_method_context(), js_method_string(name), getFunc, setFunc) + +#define JS_CLASS_INTERFACE(class, name) \ + JSCopyablePersistentFunctionHandle class::_constructor; \ + void class::Init(v8::Isolate* isolate, v8::Handle exports) {\ + v8::HandleScope scope(isolate); \ + std::string className = name; \ + v8::Local tpl = OSS::JS::JSObjectWrap::ExportConstructorTemplate(isolate, name, exports); + +#define JS_CLASS_METHOD_DEFINE(class, name, method) OSS::JS::JSObjectWrap::ExportMethod(isolate, tpl, name, method) + +#define JS_CLASS_INDEX_ACCESSOR_DEFINE(class, getter, setter) OSS::JS::JSObjectWrap::ExportIndexHandler(isolate, tpl, getter, setter); +#define JS_CLASS_INTERFACE_END(class) } OSS::JS::JSObjectWrap::FinalizeConstructorTemplate(isolate, className.c_str(), tpl, exports); +#define js_export_class(class) class::Init(js_method_isolate(), exports) + +#define JS_EXPORTS_INIT() static void init_exports(JSCallbackInfo _args_) { \ + js_method_enter_scope(); \ + v8::Local exports = v8::Local::New(js_method_isolate(),v8::Object::New(js_method_isolate())); + +#define js_export_finalize() } _args_.GetReturnValue().Set(exports); -#define js_method_arg_type(Type, Var, Index, Func, Msg) \ - Type Var; \ - if (Index >= _args_.Length()) \ - js_throw("Invalid Argument Count"); \ - if (!Func(Var, _args_[Index])) \ - js_throw(Msg); -#define js_method_arg_declare_bool(Var, Index) js_method_arg_type(bool, Var, Index, js_assign_bool, "Invalid Type. Expecting Bool") -#define js_method_arg_declare_uint32(Var, Index) js_method_arg_type(uint32_t, Var, Index, js_assign_uint32, "Invalid Type. Expecting UInt32") -#define js_method_arg_declare_int32(Var, Index) js_method_arg_type(int32_t, Var, Index, js_assign_int32, "Invalid Type. Expecting Int32") -#define js_method_arg_declare_number(Var, Index) js_method_arg_type(double, Var, Index, js_assign_number, "Invalid Type. Expecting Nymber") -#define js_method_arg_declare_string(Var, Index) js_method_arg_type(std::string, Var, Index, js_assign_string, "Invalid Type. Expecting String") -#define js_method_arg_declare_array(Var, Index) js_method_arg_type(JSArrayHandle, Var, Index, js_assign_array, "Invalid Type. Expecting Array") -#define js_method_arg_declare_object(Var, Index) js_method_arg_type(JSObjectHandle, Var, Index, js_assign_object, "Invalid Type. Expecting Object") -#define js_method_arg_declare_unwrapped_object(CLASS, VAR, INDEX) js_method_arg_declare_object(_##VAR##__temp, INDEX); CLASS* VAR = js_unwrap_object(CLASS, _##VAR##__temp->ToObject()) -#define js_method_arg_declare_external_object(Class, Var, Index) js_method_arg_type(Class*, Var, Index, js_assign_external_object, "Invalid Type. Expecting External Object") -#define js_method_arg_declare_function(Var, Index) js_method_arg_type(JSLocalFunctionHandle, Var, Index, js_assign_function, "Invalid Type. Expecting Function") -#define js_method_arg_declare_persistent_function(Var, Index) js_method_arg_type(JSPersistentFunctionHandle, Var, Index, js_assign_persistent_function, "Invalid Type. Expecting Function") -#define js_method_arg_declare_self(Class, Var) Class* Var = js_method_arg_unwrap_self(Class) - -#define js_method_declare_isolate(Var) OSS::JS::JSIsolate::Ptr Var = OSS::JS::JSIsolateManager::instance().getIsolate(); \ - if (!Var) { js_throw("Unable to retrieve isolate"); } +// Value Definitions +// +#define JSPersistentFunctionCast(handle) JSPersistentFunctionHandle::New(JSFunctionHandle::Cast(handle)) -#define js_function_call(Func, Data, Size) Func->Call(js_get_global(), Size, Data) +#define js_function_call(function, data, size) function->Call(js_method_context(), js_method_global(), size, data) template -bool js_assign_external_object(T*& value, const JSValueHandle& handle) +bool js_method_assign_external_object(JSCallbackInfo _args_, T*& value, const JSValueHandle& handle) { if (!handle->IsObject()) { return false; } - value = js_unwrap_object(T, handle->ToObject()); + value = js_unwrap_object(T, handle->ToObject(js_method_context()).ToLocalChecked()); return true; } -inline bool js_assign_persistent_function(JSPersistentFunctionHandle& value, const JSValueHandle& handle) +inline bool js_method_assign_persistent_function(JSCallbackInfo _args_, JSCopyablePersistentFunctionHandle& value, const JSValueHandle& handle) { if (!handle->IsFunction()) { return false; } - value = v8::Persistent::New(v8::Handle::Cast(handle)); + JSFunctionHandle functionHandle = JSFunctionHandle::Cast(handle); + value = JSCopyablePersistentFunctionHandle(js_method_isolate(),functionHandle); return true; } -inline bool js_assign_function(JSLocalFunctionHandle& value, const JSValueHandle& handle) +inline bool js_method_assign_function(JSCallbackInfo _args_, JSLocalFunctionHandle& value, const JSValueHandle& handle) { if (!handle->IsFunction()) { return false; } - value = v8::Local::New(v8::Handle::Cast(handle)); + value = JSLocalFunctionHandle::New(js_method_isolate(),v8::Handle::Cast(handle)); return true; } -inline bool js_assign_uint32(uint32_t& value, const JSValueHandle& handle) +inline bool js_method_assign_uint32(JSCallbackInfo _args_, uint32_t& value, const JSValueHandle& handle) { if (!handle->IsUint32()) { return false; } - value = handle->ToUint32()->Value(); + value = handle->ToUint32(js_method_context()).ToLocalChecked()->Value(); return true; } -inline bool js_assign_int32(int32_t& value, const JSValueHandle& handle) +inline bool js_method_assign_int32(JSCallbackInfo _args_, int32_t& value, const JSValueHandle& handle) { if (!handle->IsInt32()) { return false; } - value = handle->ToInt32()->Value(); + value = handle->ToInt32(js_method_context()).ToLocalChecked()->Value(); return true; } -inline bool js_assign_number(double& value, const JSValueHandle& handle) +inline bool js_method_assign_number(JSCallbackInfo _args_, double& value, const JSValueHandle& handle) { if (!handle->IsNumber()) { return false; } - value = handle->ToNumber()->Value(); + value = handle->ToNumber(js_method_context()).ToLocalChecked()->Value(); return true; } -inline bool js_assign_array(JSArrayHandle& value, const JSValueHandle& handle) +inline bool js_method_assign_array(JSCallbackInfo _args_, JSArrayHandle& value, const JSValueHandle& handle) { if (!handle->IsArray()) { @@ -300,66 +370,80 @@ inline bool js_assign_array(JSArrayHandle& value, const JSValueHandle& handle) return true; } -inline bool js_assign_string(std::string& value, const JSValueHandle& handle) +inline bool js_method_assign_string(JSCallbackInfo _args_, std::string& value, const JSValueHandle& handle) { if (!handle->IsString()) { return false; } - value = (const char*) (*v8::String::Utf8Value(handle)); + value = (const char*) (*v8::String::Utf8Value(js_method_isolate(),handle)); return true; } -inline bool js_assign_bool(bool& value, const JSValueHandle& handle) +inline bool js_method_assign_bool(JSCallbackInfo _args_, bool& value, const JSValueHandle& handle) { if (!handle->IsBoolean()) { return false; } - value = handle->ToBoolean()->Value(); + value = handle->ToBoolean(js_method_isolate())->Value(); return true; } -inline bool js_assign_object(JSObjectHandle& value, const JSValueHandle& handle) +inline bool js_method_assign_object(JSCallbackInfo _args_, JSObjectHandle& value, const JSValueHandle& handle) { if (!handle->IsObject()) { return false; } - value = handle->ToObject(); + value = handle->ToObject(js_method_context()).ToLocalChecked(); return true; } -inline void js_assign_persistent_arg_vector(JSPersistentArgumentVector& output, const JSValueHandle& handle) +inline void js_assign_persistent_arg_vector(v8::Isolate* isolate, JSCopyablePersistentArgumentVector& output, const JSValueHandle& handle) { if (handle->IsArray()) { v8::Handle arrayArg = v8::Handle::Cast(handle); for (std::size_t i = 0; i Length(); i++) { - output.push_back(v8::Persistent::New(arrayArg->Get(i))); + v8::Handle arrayItem = arrayArg->Get(isolate->GetCurrentContext(),i).ToLocalChecked(); + output.push_back(v8::Persistent(isolate,arrayItem)); } } else { - output.push_back(v8::Persistent::New(handle)); + output.push_back(v8::Persistent(isolate,handle)); } } +//inline void js_assign_persistent_arg_vector(JSCopyablePersistentArgumentVector& output, const JSValueHandle& handle) +//{ +// js_assign_persistent_arg_vector( js_get_v8_isolate(), output, handle ); +//} + +//inline void js_method_assign_persistent_arg_vector(JSCopyablePersistentArgumentVector& output, const JSValueHandle& handle) +//{ +// js_assign_persistent_arg_vector( js_method_isolate(), output, handle ); +//} + -inline JSObjectHandle js_wrap_pointer_to_local_object(void* ptr) + +inline JSObjectHandle js_method_wrap_pointer_to_local_object(JSCallbackInfo _args_, void* ptr) { - JSLocalObjectTemplateHandle objectTemplate = JSObjectTemplate(); + JSLocalObjectTemplateHandle objectTemplate = JSObjectTemplate(js_method_isolate()); objectTemplate->SetInternalFieldCount(1); - JSLocalObjectTemplateHandle classTemplate = JSLocalObjectTemplateHandle::New(objectTemplate); - JSObjectHandle JSObjectWrapper = classTemplate->NewInstance(); - JSExternalHandle objectPointer = JSExternal(ptr); + JSLocalObjectTemplateHandle classTemplate = JSLocalObjectTemplateHandle::New(js_method_isolate(),objectTemplate); + JSObjectHandle JSObjectWrapper = classTemplate->NewInstance(js_method_context()).ToLocalChecked(); + JSExternalHandle objectPointer = JSExternal(js_method_isolate(),ptr); JSObjectWrapper->SetInternalField(0, objectPointer); return JSObjectWrapper; } +#define js_method_wrap_pointer_to_local_object(ptr) js_method_wrap_pointer_to_local_object(_args_,ptr) + template T* js_unwrap_pointer_from_local_object(JSObjectHandle obj, uint32_t index = 0) { @@ -367,6 +451,120 @@ T* js_unwrap_pointer_from_local_object(JSObjectHandle obj, uint32_t index = 0) return static_cast(ptr->Value()); } +#define js_method_set_return_arg(value) _args_.GetReturnValue().Set(value) + +inline bool js_method_set_return(JSCallbackInfo _args_, const JSValueHandle& handle ) +{ + if (!handle->IsObject()) + { + js_method_set_return_arg(js_method_undefined()); + return false; + } + js_method_set_return_arg(handle); + return true; +} + +inline bool js_method_set_return(JSAccessorInfo _args_, const JSValueHandle& handle ) +{ + if (!handle->IsObject()) + { + js_method_set_return_arg(js_method_undefined()); + return false; + } + js_method_set_return_arg(handle); + return true; +} + +#define js_method_set_return_handle(handle) js_method_set_return(_args_,handle) + +#define js_method_set_return_string(value) js_method_set_return_handle(js_method_string(value)) + +#define js_method_set_return_boolean(value) js_method_set_return_handle(js_method_boolean(value)) +#define js_method_set_return_false() js_method_set_return_boolean(false) +#define js_method_set_return_true() js_method_set_return_boolean(true) + +#define js_method_set_return_integer(value) js_method_set_return_handle(js_method_integer(value)) + +inline bool js_method_set_return_undefined(JSCallbackInfo _args_) +{ + js_method_set_return_arg(js_method_undefined()); + return true; +} + +inline bool js_method_set_return_undefined(JSAccessorInfo _args_) +{ + js_method_set_return_arg(js_method_undefined()); + return true; +} + + +#define js_method_set_return_undefined() js_method_set_return_undefined(_args_) + +#define js_method_set_return_self() js_method_set_return_arg(js_method_self()) + +inline void handle_to_persistent_arg_vector(v8::Isolate* isolate, JSValueHandle input, JSCopyablePersistentArgumentVector& output) +{ + if (input->IsArray()) + { + JSArrayHandle arrayArg = JSArrayHandle::Cast(input); + for (std::size_t i = 0; i < arrayArg->Length(); i++) + { + JSValueHandle item = JSValueHandle::New(isolate,arrayArg->Get(isolate->GetCurrentContext(),i).ToLocalChecked()); + output.push_back(JSPersistentValueHandle(isolate,item)); + } + } + else + { + output.push_back(JSPersistentValueHandle(isolate,input)); + } +} + +//inline void handle_to_persistent_arg_vector(JSValueHandle input, JSCopyablePersistentArgumentVector& output) +//{ +// handle_to_persistent_arg_vector( js_get_v8_isolate(), input, output ); +//} + + +inline void handle_to_arg_vector(v8::Isolate* isolate, JSValueHandle input, JSArgumentVector& output) +{ + if (input->IsArray()) + { + JSArrayHandle arrayArg = JSArrayHandle::Cast(input); + for (std::size_t i = 0; i < arrayArg->Length(); i++) + { + JSValueHandle item = JSValueHandle::New(isolate,arrayArg->Get(isolate->GetCurrentContext(),i).ToLocalChecked()); + output.push_back(item); + } + } + else + { + output.push_back(input); + } +} + +//inline void handle_to_arg_vector(JSValueHandle input, JSArgumentVector& output) +//{ +// handle_to_arg_vector( js_get_v8_isolate(), input, output ); +//} + + +inline void persistent_arg_vector_to_arg_vector(v8::Isolate* isolate, const JSCopyablePersistentArgumentVector& input, JSArgumentVector& output) +{ + for (JSCopyablePersistentArgumentVector::const_iterator iter = input.begin(); iter != input.end(); iter++) + { + JSValueHandle item = JSValueHandle::New(isolate, *iter); + output.push_back(item); + } +} + +//inline void persistent_arg_vector_to_arg_vector(const JSCopyablePersistentArgumentVector& input, JSArgumentVector& output) +//{ +// persistent_arg_vector_to_arg_vector( js_get_v8_isolate(), input, output); +//} + + + + #endif // OSS_JS_INCLUDED diff --git a/include/OSS/JS/JSFileDescriptor.h b/include/OSS/JS/JSFileDescriptor.h index 97f8d8ef9e..a3dd3b7673 100644 --- a/include/OSS/JS/JSFileDescriptor.h +++ b/include/OSS/JS/JSFileDescriptor.h @@ -40,16 +40,14 @@ class JSFileDescriptor public: typedef boost::shared_ptr Ptr; JSFileDescriptor(); - JSFileDescriptor(v8::Handle ioHandler, int fd, int events); + JSFileDescriptor(v8::Isolate* isolate, v8::Handle ioHandler, int fd, int events); ~JSFileDescriptor(); - void setFileDescriptor(int fd); int getFileDescriptor() const; - void setIoHandler(v8::Handle ioHandler); - const v8::Persistent& getIoHandler() const; + const JSCopyablePersistentFunctionHandle& getIoHandler() const; pollfd& pollFd(); - void signalIO(pollfd pfd); + void signalIO(v8::Isolate* isolate, pollfd pfd); protected: - v8::Persistent _ioHandler; + JSCopyablePersistentFunctionHandle _ioHandler; pollfd _pollfd; }; @@ -60,9 +58,9 @@ inline JSFileDescriptor::JSFileDescriptor() { } -inline JSFileDescriptor::JSFileDescriptor(v8::Handle ioHandler, int fd, int events) +inline JSFileDescriptor::JSFileDescriptor(v8::Isolate* isolate, v8::Handle ioHandler, int fd, int events) { - _ioHandler = v8::Persistent::New(v8::Handle::Cast(ioHandler)); + _ioHandler = JSCopyablePersistentFunctionHandle(isolate, v8::Handle::Cast(ioHandler)); _pollfd.fd = fd; _pollfd.events = events; } @@ -71,26 +69,17 @@ inline JSFileDescriptor::~JSFileDescriptor() { if (!_ioHandler.IsEmpty()) { - _ioHandler.Dispose(); + _ioHandler.Reset(); } } -inline void JSFileDescriptor::setFileDescriptor(int fd) -{ - _pollfd.fd = fd; -} - inline int JSFileDescriptor::getFileDescriptor() const { return _pollfd.fd; } -inline void JSFileDescriptor::setIoHandler(v8::Handle ioHandler) -{ - _ioHandler = v8::Persistent::New(v8::Handle::Cast(ioHandler)); -} -inline const v8::Persistent& JSFileDescriptor::getIoHandler() const +inline const JSCopyablePersistentFunctionHandle& JSFileDescriptor::getIoHandler() const { return _ioHandler; } @@ -100,15 +89,21 @@ inline pollfd& JSFileDescriptor::pollFd() return _pollfd; } -inline void JSFileDescriptor::signalIO(pollfd pfd) +inline void JSFileDescriptor::signalIO(v8::Isolate* isolate, pollfd pfd) { + v8::Local context = isolate->GetCurrentContext(); + v8::Local global = context->Global(); + std::vector< v8::Local > args(2); - args[0] = v8::Int32::New(pfd.fd); - args[1] = v8::Int32::New(pfd.revents); - v8::Local context = v8::Context::GetCalling(); - assert(!context.IsEmpty()); + args[0] = v8::Int32::New(isolate, pfd.fd); + args[1] = v8::Int32::New(isolate, pfd.revents); + // v8::Local context = v8::Context::GetCalling(); + // NB! Both GetCalling and Isolate::GetCallingContext have been removed: + // "Calling context concept is not compatible with tail calls and will be removed." + //assert(!context.IsEmpty()); assert(!_ioHandler.IsEmpty()); - _ioHandler->Call(context->Global(), args.size(), args.data()); + JSFunctionHandle ioFunctionHandler = JSFunctionHandle::New(isolate,_ioHandler); + ioFunctionHandler->Call(context, global, args.size(), args.data()); } diff --git a/include/OSS/JS/JSFileDescriptorManager.h b/include/OSS/JS/JSFileDescriptorManager.h index acc408c7c9..8b6a5813e4 100644 --- a/include/OSS/JS/JSFileDescriptorManager.h +++ b/include/OSS/JS/JSFileDescriptorManager.h @@ -42,17 +42,17 @@ class JSFileDescriptorManager : public JSEventLoopComponent JSFileDescriptorManager(JSEventLoop* pEventLoop); ~JSFileDescriptorManager(); - void addFileDescriptor(int fd, v8::Handle ioHandler, int events); + void addFileDescriptor(v8::Isolate* isolate, int fd, v8::Handle ioHandler, int events); bool removeFileDescriptor(int fd); JSFileDescriptor::Ptr findDescriptor(int fd); void appendDescriptors(Descriptors& descriptors); - bool signalIO(pollfd pfd); + bool signalIO(v8::Isolate* isolate, pollfd pfd); // // Methods exposed to javascript // - static v8::Handle monitor_descriptor(const v8::Arguments& args); - static v8::Handle unmonitor_descriptor(const v8::Arguments& args); + JS_METHOD_DECLARE(monitor_descriptor); + JS_METHOD_DECLARE(unmonitor_descriptor); private: OSS::mutex_critic_sec _descriptorsMutex; diff --git a/include/OSS/JS/JSFunctionCallback.h b/include/OSS/JS/JSFunctionCallback.h index 5e2b015b9b..bc19ef0896 100644 --- a/include/OSS/JS/JSFunctionCallback.h +++ b/include/OSS/JS/JSFunctionCallback.h @@ -38,28 +38,34 @@ namespace JS { class JSFunctionCallback : public boost::enable_shared_from_this, private boost::noncopyable { public: - typedef std::vector< v8::Persistent > ArgumentVector; typedef boost::shared_ptr Ptr; - JSFunctionCallback(v8::Handle func); - JSFunctionCallback(v8::Handle func, v8::Handle args); - JSFunctionCallback(v8::Handle func, v8::Handle args, v8::Handle resultHandler); + JSFunctionCallback(JSValueHandle func); + JSFunctionCallback(JSValueHandle func, JSValueHandle args); + JSFunctionCallback(JSValueHandle func, JSValueHandle args, JSValueHandle resultHandler); virtual ~JSFunctionCallback(); virtual void execute(); - void handle_to_arg_vector(v8::Handle input, ArgumentVector& output); void dispose(); bool& autoDisposeOnExecute(); bool autoDisposeOnExecute() const; + private: - v8::Persistent _function; - ArgumentVector _args; - v8::Persistent _resultHandler; + v8::Isolate* getV8Isolate(); + + JSCopyablePersistentFunctionHandle _function; + JSCopyablePersistentArgumentVector _args; + JSCopyablePersistentFunctionHandle _resultHandler; bool _disposed; bool _autoDisposeOnExecute; OSS::mutex_critic_sec _disposeMutex; }; +inline v8::Isolate* JSFunctionCallback::getV8Isolate() +{ + return js_get_v8_isolate(); +} + inline bool& JSFunctionCallback::autoDisposeOnExecute() { return _autoDisposeOnExecute; @@ -70,28 +76,28 @@ inline bool JSFunctionCallback::autoDisposeOnExecute() const return _autoDisposeOnExecute; } -inline JSFunctionCallback::JSFunctionCallback(v8::Handle func) : +inline JSFunctionCallback::JSFunctionCallback(JSValueHandle func) : _disposed(false), _autoDisposeOnExecute(false) { - _function = v8::Persistent::New(v8::Handle::Cast(func)); + _function = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( func ) )); } -inline JSFunctionCallback::JSFunctionCallback(v8::Handle func, v8::Handle args) : +inline JSFunctionCallback::JSFunctionCallback(JSValueHandle func, v8::Handle args) : _disposed(false), _autoDisposeOnExecute(false) { - _function = v8::Persistent::New(v8::Handle::Cast(func)); - handle_to_arg_vector(args, _args); + _function = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( func ) )); + handle_to_persistent_arg_vector(getV8Isolate(), args, _args); } -inline JSFunctionCallback::JSFunctionCallback(v8::Handle func, v8::Handle args, v8::Handle resultHandler) : +inline JSFunctionCallback::JSFunctionCallback(JSValueHandle func, v8::Handle args, v8::Handle resultHandler) : _disposed(false), _autoDisposeOnExecute(false) { - _function = v8::Persistent::New(v8::Handle::Cast(func)); - _resultHandler = v8::Persistent::New(v8::Handle::Cast(resultHandler)); - handle_to_arg_vector(args, _args); + _function = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( func ) )); + _resultHandler = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( resultHandler ) )); + handle_to_persistent_arg_vector(getV8Isolate(), args, _args); } inline JSFunctionCallback::~JSFunctionCallback() @@ -108,46 +114,43 @@ inline void JSFunctionCallback::dispose() return; } - _function.Dispose(); + _function.Reset(); if (!_resultHandler.IsEmpty()) { - _resultHandler.Dispose(); + _resultHandler.Reset(); } - for (ArgumentVector::iterator iter = _args.begin(); iter != _args.end(); iter++) + for (JSCopyablePersistentArgumentVector::iterator iter = _args.begin(); iter != _args.end(); iter++) { - iter->Dispose(); + iter->Reset(); } _disposed = true; } -inline void JSFunctionCallback::handle_to_arg_vector(v8::Handle input, ArgumentVector& output) -{ - if (input->IsArray()) - { - v8::Handle arrayArg = v8::Handle::Cast(input); - for (std::size_t i = 0; i Length(); i++) - { - output.push_back(v8::Persistent::New(arrayArg->Get(i))); - } - } - else - { - output.push_back(v8::Persistent::New(input)); - } -} - inline void JSFunctionCallback::execute() { + v8::Local context = getV8Isolate()->GetCurrentContext(); + v8::Local global = context->Global(); + + JSLocalArgumentVector args; + persistent_arg_vector_to_arg_vector(getV8Isolate(),_args, args); + + JSFunctionHandle func = JSFunctionHandle::New(getV8Isolate(),_function); if (_resultHandler.IsEmpty()) { - _function->Call(js_get_global(), _args.size(), _args.data()); + func->Call(context, global, args.size(), args.data()); } else { - v8::Handle result = _function->Call(js_get_global(), _args.size(), _args.data()); - ArgumentVector resultArg; - handle_to_arg_vector(result, resultArg); - _resultHandler->Call(js_get_global(), resultArg.size(), resultArg.data()); + v8::MaybeLocal maybeResult = + func->Call(context, global, args.size(), args.data()); + if( !maybeResult.IsEmpty() ) + { + JSValueHandle result = maybeResult.ToLocalChecked(); + JSArgumentVector resultArg; + handle_to_arg_vector(getV8Isolate(), result, resultArg); + JSFunctionHandle resultHandler = JSFunctionHandle::New(getV8Isolate(),_resultHandler); + resultHandler->Call(context, global, resultArg.size(), resultArg.data()); + } } if (_autoDisposeOnExecute) diff --git a/include/OSS/JS/JSInterIsolateCallManager.h b/include/OSS/JS/JSInterIsolateCallManager.h index 7e80cb669d..f7ea535808 100644 --- a/include/OSS/JS/JSInterIsolateCallManager.h +++ b/include/OSS/JS/JSInterIsolateCallManager.h @@ -38,7 +38,6 @@ class JSInterIsolateCallManager : public JSEventLoopComponent { public: typedef std::queue CallQueue; - typedef JSPersistentValue Handler; typedef JSInterIsolateCall::Request Request; typedef JSInterIsolateCall::Result Result; @@ -50,7 +49,7 @@ class JSInterIsolateCallManager : public JSEventLoopComponent void notify(const Request& request, void* userData, JSPersistentFunctionHandle* cb); bool execute(const std::string& request, std::string& result, uint32_t timeout, void* userData); bool execute(const Request& request, Result& result, uint32_t timeout, void* userData); - void setHandler(const JSPersistentFunctionHandle& handler); + void setHandler(const JSCopyablePersistentFunctionHandle& handler); bool doOneWork(); bool isEnabled(); protected: @@ -58,7 +57,7 @@ class JSInterIsolateCallManager : public JSEventLoopComponent JSInterIsolateCall::Ptr dequeue(); OSS::mutex_critic_sec _queueMutex; CallQueue _queue; - Handler _handler; + JSCopyablePersistentFunctionHandle _handler; friend class JSEventLoop; }; @@ -66,14 +65,14 @@ class JSInterIsolateCallManager : public JSEventLoopComponent // Inlines // -inline void JSInterIsolateCallManager::setHandler(const JSPersistentFunctionHandle& handler) +inline void JSInterIsolateCallManager::setHandler(const JSCopyablePersistentFunctionHandle& handler) { _handler = handler; } inline bool JSInterIsolateCallManager::isEnabled() { - return !_handler.empty(); + return !_handler.IsEmpty(); } } } diff --git a/include/OSS/JS/JSIsolate.h b/include/OSS/JS/JSIsolate.h index bd414cea2a..d8e36f49ab 100644 --- a/include/OSS/JS/JSIsolate.h +++ b/include/OSS/JS/JSIsolate.h @@ -47,10 +47,6 @@ class JSIsolate : public boost::enable_shared_from_this { public: typedef boost::shared_ptr Ptr; - typedef JSPersistentValue Context; - typedef JSPersistentValue ObjectTemplate; - typedef JSPersistentValue Global; - typedef JSPersistentValue GlobalTemplate; typedef JSInterIsolateCall::Request Request; typedef JSInterIsolateCall::Result Result; typedef boost::function Task; @@ -129,9 +125,9 @@ class JSIsolate : public boost::enable_shared_from_this void internal_run(); - Context _context; - ObjectTemplate _objectTemplate; - GlobalTemplate _globalTemplate; + JSCopyablePersistentContextHandle _context; + JSCopyablePersistentObjectTemplateHandle _objectTemplate; + JSCopyablePersistentObjectTemplateHandle _globalTemplate; v8::Isolate* _pIsolate; JSModule* _pModuleManager; diff --git a/include/OSS/JS/JSIsolateManager.h b/include/OSS/JS/JSIsolateManager.h index eebfa6faa8..30cb7f0729 100644 --- a/include/OSS/JS/JSIsolateManager.h +++ b/include/OSS/JS/JSIsolateManager.h @@ -34,14 +34,14 @@ namespace OSS { namespace JS { - + class JSIsolateManager : boost::noncopyable { public: typedef std::map MapByName; typedef std::map MapByThreadId; typedef std::map ExternalData; - typedef std::map GlobalExports; + typedef std::map GlobalExports; typedef boost::function GlobalExportFunc; typedef std::vector GlobalExportVector; @@ -78,10 +78,10 @@ class JSIsolateManager : boost::noncopyable /// Attach a named pointer to the isolate manager. /// This is used internally to expose global C++ objects to plugins - void exportMethod(const std::string& funcName, JS_METHOD_FUNC method); + void exportMethod(const std::string& funcName, v8::FunctionCallback method); /// Add a method to be exported globally for all isolates - void initGlobalExports(JSObjectTemplateHandle& global); + void initGlobalExports(v8::Isolate* isolate, JSObjectTemplateHandle& global); /// Register all exported methods void resetRootIsolate(); @@ -115,7 +115,7 @@ inline OSS::mutex& JSIsolateManager::modulesMutex() return _modulesMutex; } -inline void JSIsolateManager::exportMethod(const std::string& funcName, JS_METHOD_FUNC method) +inline void JSIsolateManager::exportMethod(const std::string& funcName, v8::FunctionCallback method) { _exports[funcName] = method; } diff --git a/include/OSS/JS/JSModule.h b/include/OSS/JS/JSModule.h index 82dbd72a4c..2f4a667eac 100644 --- a/include/OSS/JS/JSModule.h +++ b/include/OSS/JS/JSModule.h @@ -51,8 +51,8 @@ class JSModule JSModule(JSIsolate* pIsolate); ~JSModule(); - bool initGlobalExports(v8::Handle& global); - bool initialize(v8::TryCatch& try_catch, v8::Handle& global); + bool initGlobalExports(v8::Isolate* isolate, v8::Handle& global); + bool initialize(v8::Isolate* isolate, v8::TryCatch& try_catch, v8::Handle& global); InternalModules& getInternalModules(); ModuleHelpers& getModuleHelpers(); @@ -64,7 +64,7 @@ class JSModule protected: void registerInternalModule(const Module& module); void registerModuleHelper(const Module& module); - bool compileModuleHelpers(v8::TryCatch& try_catch, v8::Handle& global); + bool compileModuleHelpers(v8::Isolate* isolate, v8::TryCatch& try_catch, v8::Handle& global); InternalModules _modules; ModuleHelpers _moduleHelpers; diff --git a/include/OSS/JS/JSObjectWrap.h b/include/OSS/JS/JSObjectWrap.h index ae0f31a19c..fbb883c419 100644 --- a/include/OSS/JS/JSObjectWrap.h +++ b/include/OSS/JS/JSObjectWrap.h @@ -44,41 +44,60 @@ class JSObjectWrap { { return 0; } - return static_cast(handle->GetPointerFromInternalField(0)); + return static_cast(handle->GetAlignedPointerFromInternalField(0)); } template - static v8::Local ExportConstructorTemplate(const char * className, v8::Handle& exports) + static v8::Local ExportConstructorTemplate( + v8::Isolate* isolate, + const char * className, + v8::Handle& exports) { - v8::Local tpl = v8::FunctionTemplate::New(T::New); - tpl->SetClassName(v8::String::NewSymbol(className)); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("ObjectType"), v8::String::NewSymbol(className)); + v8::Local tpl = v8::FunctionTemplate::New(isolate,T::New); + tpl->SetClassName(v8::String::NewFromUtf8(isolate,className).ToLocalChecked()); + tpl->PrototypeTemplate()->Set( + v8::String::NewFromUtf8(isolate,"ObjectType").ToLocalChecked(), + v8::String::NewFromUtf8(isolate,className).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); return tpl; } template - static void FinalizeConstructorTemplate(const char * className, v8::Local& tpl, v8::Handle& exports) + static void FinalizeConstructorTemplate( + v8::Isolate* isolate, + const char * className, + v8::Local& tpl, + v8::Handle& exports) { - T::_constructor = v8::Persistent::New(tpl->GetFunction()); - exports->Set(v8::String::NewSymbol(className), T::_constructor); + v8::Local constructorHandle = tpl->GetFunction(isolate->GetCurrentContext()).ToLocalChecked(); + + T::_constructor = v8::Persistent>(isolate, constructorHandle); + + exports->Set(isolate->GetCurrentContext(), v8::String::NewFromUtf8(isolate,className).ToLocalChecked(), constructorHandle); + } template - static void ExportMethod(v8::Local& tpl, const char* method, v8::InvocationCallback callback) + static void ExportMethod( + v8::Isolate* isolate, + v8::Local& tpl, + const char* method, + v8::FunctionCallback callback) { - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol(method), v8::FunctionTemplate::New(callback)->GetFunction()); + tpl->PrototypeTemplate()->Set( + v8::String::NewFromUtf8(isolate,method).ToLocalChecked(), + v8::FunctionTemplate::New(isolate,callback)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()); } template - static void ExportIndexHandler(v8::Local& tpl, v8::IndexedPropertyGetter getter, v8::IndexedPropertySetter setter = 0) + static void ExportIndexHandler(v8::Isolate* isolate, v8::Local& tpl, v8::IndexedPropertyGetterCallback getter, v8::IndexedPropertySetterCallback setter = 0) { tpl->PrototypeTemplate()->SetIndexedPropertyHandler(getter, setter); } JSIsolate* getIsolate(); - v8::Persistent handle_; // ro + v8::Persistent> handle_; // ro protected: void Wrap (v8::Handle handle); @@ -107,7 +126,7 @@ class JSObjectWrap { void* _pIsolatePtr; private: - static void WeakCallback (v8::Persistent value, void *data); + static void WeakCallback(const v8::WeakCallbackInfo& data); }; // diff --git a/include/OSS/JS/JSPersistentValue.h b/include/OSS/JS/JSPersistentValue.h index 70f66b131b..d30427bde5 100644 --- a/include/OSS/JS/JSPersistentValue.h +++ b/include/OSS/JS/JSPersistentValue.h @@ -88,7 +88,7 @@ class JSPersistentValue { if (!_value.IsEmpty()) { - _value.Dispose(); + _value.Reset(); } } diff --git a/include/OSS/JS/JSPlugin.h b/include/OSS/JS/JSPlugin.h index b9b968ca8c..8906e53579 100644 --- a/include/OSS/JS/JSPlugin.h +++ b/include/OSS/JS/JSPlugin.h @@ -37,7 +37,7 @@ class JSPlugin JSPlugin(); virtual ~JSPlugin(); virtual std::string name() const = 0; - virtual bool initExportFunc(std::string& funcName) = 0; + virtual bool initExportFunc(v8::Isolate* isolate, std::string& funcName) = 0; static Poco::ThreadPool* _pThreadPool; }; @@ -59,14 +59,16 @@ class Class : public JSPlugin \ public: \ Class(); \ virtual std::string name() const; \ - virtual bool initExportFunc(std::string& funcName); \ + virtual bool initExportFunc(v8::Isolate* isolate, std::string& funcName); \ }; \ Class::Class() {} \ std::string Class::name() const { return #Class; } \ -bool Class::initExportFunc(std::string& funcName) \ +bool Class::initExportFunc(v8::Isolate* isolate, std::string& funcName) \ { \ + v8::Local context = isolate->GetCurrentContext(); \ + v8::Local global = context->Global(); \ funcName = "__" #Class "_init_exports"; \ - js_get_global()->Set(v8::String::New(funcName.c_str()), v8::FunctionTemplate::New(init_exports)->GetFunction()); \ + global->Set(context,JSString(isolate,funcName.c_str()), v8::FunctionTemplate::New(isolate,init_exports)->GetFunction(context).ToLocalChecked()); \ return true; \ } \ extern "C" { \ diff --git a/include/OSS/JS/JSUtil.h b/include/OSS/JS/JSUtil.h index d5bef671fa..74c9efdd63 100644 --- a/include/OSS/JS/JSUtil.h +++ b/include/OSS/JS/JSUtil.h @@ -25,51 +25,59 @@ #include "v8.h" #include "OSS/UTL/CoreUtils.h" - +#include namespace OSS { namespace JS { +std::string string_from_js_string(v8::Isolate* isolate, v8::Handle str); std::string string_from_js_string(v8::Handle str); -std::string string_from_js_value(const v8::Handle& str); + +std::string string_from_js_value(v8::Isolate* isolate, const v8::Handle& str); +std::string string_from_js_value(v8::Handle str); + const char* cstring_from_js_string(const v8::String::Utf8Value& value); -v8::Handle read_file(const std::string& name); -v8::Handle read_file_skip_shebang(const std::string& name, bool hasCommonJs = false); -v8::Handle read_directory(const boost::filesystem::path& directory); + +std::string read_file(const std::string& name); +std::string read_file_skip_shebang(const std::string& name, bool hasCommonJs = false); +std::string read_directory(const boost::filesystem::path& directory); // // Logging // -void report_js_exception(v8::TryCatch &try_catch, bool show_line); -v8::Handle log_info_callback(const v8::Arguments& args); -v8::Handle log_debug_callback(const v8::Arguments& args); -v8::Handle log_error_callback(const v8::Arguments& args); +void report_js_exception(v8::Isolate* isolate, v8::TryCatch &try_catch, bool show_line); +JS_GLOBAL_FUNCTION_DECLARE(log_info_callback); +JS_GLOBAL_FUNCTION_DECLARE(log_debug_callback); +JS_GLOBAL_FUNCTION_DECLARE(log_error_callback); // // Unwrap C++ Object // template -static T* unwrap_external_object(const v8::Arguments& args) +static T* unwrap_external_object(JSCallbackInfo args) { if (args.Length() < 1) return 0; v8::Handle obj = args[0]; if (!obj->IsObject()) return 0; - v8::Handle field = v8::Handle::Cast(obj->ToObject()->GetInternalField(0)); + v8::Handle field = v8::Handle::Cast(obj->ToObject(args.GetIsolate()->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); void* ptr = field->Value(); return static_cast(ptr); } +/* Not used void wrap_external_object(v8::Persistent* pContext, v8::Persistent* pRequestTemplate, v8::Handle& objectInstance, OSS_HANDLE pObject); + */ + -std::string get_stack_trace(v8::Handle message, uint32_t bufLen); +std::string get_stack_trace(v8::Isolate* isolate, v8::Handle message, uint32_t bufLen); -} } +}} #endif // ENABLE_FEATURE_V8 diff --git a/include/OSS/JS/modules/Async.h b/include/OSS/JS/modules/Async.h index a2196ab00e..2f79b8fa27 100644 --- a/include/OSS/JS/modules/Async.h +++ b/include/OSS/JS/modules/Async.h @@ -42,7 +42,7 @@ typedef boost::future AsyncFuture; struct Async { static pthread_t _threadId; - static v8::Persistent _externalPointerTemplate; + static JSCopyablePersistentObjectTemplateHandle _externalPointerTemplate; static void unmonitor_fd(const OSS::JS::JSIsolate::Ptr& pIsolate, int fd); // Forcibly unmonitor a particular file handle. Use with extreme caution. diff --git a/include/OSS/JS/modules/BufferObject.h b/include/OSS/JS/modules/BufferObject.h index b3c94e1dfe..2b2ce47d30 100644 --- a/include/OSS/JS/modules/BufferObject.h +++ b/include/OSS/JS/modules/BufferObject.h @@ -55,9 +55,9 @@ class BufferObject : public OSS::JS::JSObjectWrap // // Helpers // - static JSValueHandle createNew(uint32_t size); - static bool isBuffer(JSValueHandle value); - static JSValueHandle isBufferObject(JSArguments& args); + static JSValueHandle createNew( v8::Isolate* isolate, uint32_t size); + static bool isBuffer(v8::Isolate* isolate, JSValueHandle value); + JS_METHOD_DECLARE(isBufferObject); ByteArray& buffer(); private: @@ -77,12 +77,12 @@ inline BufferObject::ByteArray& BufferObject::buffer() } typedef std::vector ByteArray; -inline bool js_byte_array_to_int_array(ByteArray& input, v8::Handle& output, std::size_t sz) +inline bool js_byte_array_to_int_array(v8::Isolate* isolate, ByteArray& input, v8::Handle& output, std::size_t sz) { uint32_t i = 0; for (ByteArray::iterator iter = input.begin(); iter != input.end(); iter++) { - output->Set(i++, v8::Int32::New(*iter)); + output->Set(isolate->GetCurrentContext(), i++, v8::Int32::New(isolate,*iter)); if (sz && i >= sz) { break; @@ -91,7 +91,7 @@ inline bool js_byte_array_to_int_array(ByteArray& input, v8::Handle& return output->Length() > 0; } -inline bool js_int_array_to_byte_array(v8::Handle& input, ByteArray& output, bool resize = false) +inline bool js_int_array_to_byte_array(v8::Isolate* isolate, v8::Handle& input, ByteArray& output, bool resize = false) { if (resize) { @@ -104,7 +104,7 @@ inline bool js_int_array_to_byte_array(v8::Handle& input, ByteArray& } for(uint32_t i = 0; i < input->Length(); i++) { - uint32_t val = input->Get(i)->ToInt32()->Value(); + uint32_t val = input->Get(isolate->GetCurrentContext(),i).ToLocalChecked()->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); if (val >= 256) { return false; diff --git a/include/OSS/JS/modules/ESLEventObject.h b/include/OSS/JS/modules/ESLEventObject.h index 79c015f793..70206324b8 100644 --- a/include/OSS/JS/modules/ESLEventObject.h +++ b/include/OSS/JS/modules/ESLEventObject.h @@ -24,7 +24,7 @@ #include "OSS/JS/JSPlugin.h" #include "OSS/Net/ESLEvent.h" -#define js_method_arg_as_esl_event(Index) js_method_arg_unwrap_object(ESLEventObject, Index) +#define js_method_arg_as_esl_event(Index) js_method_unwrap_object(ESLEventObject, Index) class ESLEventObject: public OSS::JS::JSObjectWrap { diff --git a/include/OSS/JS/modules/QueueObject.h b/include/OSS/JS/modules/QueueObject.h index 0e2223e6ba..fa0de5e459 100644 --- a/include/OSS/JS/modules/QueueObject.h +++ b/include/OSS/JS/modules/QueueObject.h @@ -37,8 +37,6 @@ class QueueObject : public OSS::JS::JSObjectWrap int fd; std::string json; }; - typedef std::vector< v8::Persistent > EventData; - typedef v8::Persistent EventCallback; typedef std::map ActiveQueues; typedef std::queue JsonQueue; @@ -46,15 +44,15 @@ class QueueObject : public OSS::JS::JSObjectWrap { public: typedef boost::shared_ptr Ptr; - QueueObject::EventData _eventData; + JSCopyablePersistentArgumentVector _eventData; Event() { } ~Event() { - for (EventData::iterator iter = _eventData.begin(); iter != _eventData.end(); iter++) + for (JSCopyablePersistentArgumentVector::iterator iter = _eventData.begin(); iter != _eventData.end(); iter++) { - iter->Dispose(); + iter->Reset(); } } }; @@ -67,7 +65,7 @@ class QueueObject : public OSS::JS::JSObjectWrap EventQueue _queue; - EventCallback _eventCallback; + JSCopyablePersistentFunctionHandle _eventCallback; private: QueueObject(); diff --git a/include/OSS/JS/modules/ZMQSocketObject.h b/include/OSS/JS/modules/ZMQSocketObject.h index f7614f552c..b4fa6601ea 100644 --- a/include/OSS/JS/modules/ZMQSocketObject.h +++ b/include/OSS/JS/modules/ZMQSocketObject.h @@ -31,20 +31,18 @@ class ZMQSocketObject : public OSS::JS::JSObjectWrap typedef OSS::ZMQ::ZMQSocket Socket; ZMQSocketObject(Socket::SocketType type); virtual ~ZMQSocketObject(); + + JS_CONSTRUCTOR_DECLARE(); - static v8::Persistent _constructor; - static void Init(v8::Handle exports); - static v8::Handle New(const v8::Arguments& args); - - static v8::Handle connect(const v8::Arguments& args); - static v8::Handle bind(const v8::Arguments& args); - static v8::Handle subscribe(const v8::Arguments& args); - static v8::Handle publish(const v8::Arguments& args); - static v8::Handle send(const v8::Arguments& args); - static v8::Handle receive(const v8::Arguments& args); - static v8::Handle close(const v8::Arguments& args); - static v8::Handle getFd(const v8::Arguments& args); - + JS_METHOD_DECLARE(connect); + JS_METHOD_DECLARE(bind); + JS_METHOD_DECLARE(subscribe); + JS_METHOD_DECLARE(publish); + JS_METHOD_DECLARE(send); + JS_METHOD_DECLARE(receive); + JS_METHOD_DECLARE(close); + JS_METHOD_DECLARE(getFd); + // // Helpers // diff --git a/oss_core.m4 b/oss_core.m4 index e93946ee5f..2c9dd68be2 100644 --- a/oss_core.m4 +++ b/oss_core.m4 @@ -12,6 +12,32 @@ AC_SUBST(OSS_CORE_VERSION_INFO) # m4_include([config/ax_cxx_compile_stdcxx.m4]) +# +# Common CXX and C Flags +# +OSS_CXX_C_FLAGS="-fmessage-length=0" +# +# Compiler warnings +# +OSS_CXX_WARNINGS="-Wall -Wformat -Wwrite-strings -Wpointer-arith -Wno-unused-result -Wno-strict-aliasing" +OSS_C_WARNINGS="-Wall -Wnested-externs -Werror=return-type -Werror=uninitialized -Wno-pointer-sign -Wno-unused-function -Wno-shift-negative-value -Wno-format-extra-args" +# +# Additional CXX and C Flags +# +CXXFLAGS="$CXXFLAGS $OSS_CXX_C_FLAGS $OSS_CXX_WARNINGS" +CFLAGS="$CFLAGS $OSS_CXX_C_FLAGS $OSS_C_WARNINGS -fno-omit-frame-pointer -fno-common -fsigned-char -fPIC" + +# +# Set C++ 14 flag if supported by compiler +# +AX_CXX_COMPILE_STDCXX([14], [], [optional]) + +# +# Used by applications building oss_core inline. In our case, we set it to nothing +# +AC_SUBST([OSS_CORE_ADDITIONAL_INCLUDES], ['']) + + # # --disable-dep-check will simply display missing # dependencies as warnings. This is useful when you @@ -464,30 +490,6 @@ OSS_CORE_SRCDIR=`pwd` AC_SUBST(OSS_CORE_SRCDIR) cd ${CURRENT_DIR} -# -# Common CXX and C Flags -# -OSS_CXX_C_FLAGS="-fmessage-length=0" -# -# Compiler warnings -# -OSS_CXX_WARNINGS="-Wall -Wformat -Wwrite-strings -Wpointer-arith -Wno-unused-result -Wno-strict-aliasing" -OSS_C_WARNINGS="-Wall -Wnested-externs -Werror=return-type -Werror=uninitialized -Wno-pointer-sign -Wno-unused-function -Wno-shift-negative-value -Wno-format-extra-args" -# -# Additional CXX and C Flags -# -CXXFLAGS="$CXXFLAGS $OSS_CXX_C_FLAGS $OSS_CXX_WARNINGS" -CFLAGS="$CFLAGS $OSS_CXX_C_FLAGS $OSS_C_WARNINGS -fno-omit-frame-pointer -fno-common -fsigned-char -fPIC" - -# -# Set C++ 11 flag if supported by compiler -# -AX_CXX_COMPILE_STDCXX([11], [], [optional]) - -# -# Used by applications building oss_core inline. In our case, we set it to nothing -# -AC_SUBST([OSS_CORE_ADDITIONAL_INCLUDES], ['']) diff --git a/src/js/JSEventEmitter.cpp b/src/js/JSEventEmitter.cpp index c72930f46f..416a6bdbe7 100644 --- a/src/js/JSEventEmitter.cpp +++ b/src/js/JSEventEmitter.cpp @@ -57,7 +57,10 @@ void JSEventEmitter::onEmitEvent(void* userData) _eventQueueMutex.unlock(); QueueObject::Event::Ptr pEvent = QueueObject::Event::Ptr(new QueueObject::Event()); - js_assign_persistent_arg_vector(pEvent->_eventData, v8::Local::New(_pEventLoop->getIsolate()->parseJSON(json))); + js_assign_persistent_arg_vector(_pEventLoop->getIsolate()->getV8Isolate(), + pEvent->_eventData, v8::Local::New( + _pEventLoop->getIsolate()->getV8Isolate() + ,_pEventLoop->getIsolate()->parseJSON(json))); _pEventLoop->queueManager().enqueue(fd, pEvent); } diff --git a/src/js/JSEventLoop.cpp b/src/js/JSEventLoop.cpp index 5e71ab103d..b786ea1a8e 100644 --- a/src/js/JSEventLoop.cpp +++ b/src/js/JSEventLoop.cpp @@ -83,7 +83,7 @@ void JSEventLoop::processEvents() _fdManager.appendDescriptors(descriptors); } int ret = ::poll(descriptors.data(), descriptors.size(), 100); - v8::HandleScope scope; + v8::HandleScope scope( pIsolate->getV8Isolate() ); if (ret == -1 || _isTerminated) { break; @@ -98,10 +98,11 @@ void JSEventLoop::processEvents() OSS::UInt64 now = OSS::getTime(); if (now - lastGarbageCollectionTime > _garbageCollectionFrequency * 1000) { - v8::V8::LowMemoryNotification(); + pIsolate->getV8Isolate()->LowMemoryNotification(); lastGarbageCollectionTime = now; } - while(!v8::V8::IdleNotification()); + // while(!pIsolate->getV8Isolate()->IdleNotification()); + // V8 6.5 API Changes: Do not use idle notification at all. This function has been a no-op for almost all calls for a while now. continue; } } @@ -114,7 +115,7 @@ void JSEventLoop::processEvents() OSS::UInt64 now = OSS::getTime(); if (now - lastGarbageCollectionTime > _garbageCollectionFrequency * 1000) { - v8::V8::LowMemoryNotification(); + pIsolate->getV8Isolate()->LowMemoryNotification(); lastGarbageCollectionTime = now; } } @@ -171,7 +172,7 @@ void JSEventLoop::processEvents() found = _queueManager.dequeue(pfd.fd); if (!found) { - found = _fdManager.signalIO(pfd); + found = _fdManager.signalIO(_pIsolate->getV8Isolate(), pfd); } } diff --git a/src/js/JSEventQueueManager.cpp b/src/js/JSEventQueueManager.cpp index b432012fa8..36c4539cba 100644 --- a/src/js/JSEventQueueManager.cpp +++ b/src/js/JSEventQueueManager.cpp @@ -81,7 +81,10 @@ bool JSEventQueueManager::dequeue(int fd) if (pEvent) { QueueObject* pQueue = iter->second; - pQueue->_eventCallback->Call(js_get_global(), pEvent->_eventData.size(), pEvent->_eventData.data()); + JSLocalArgumentVector eventData; + persistent_arg_vector_to_arg_vector(getIsolate()->getV8Isolate(),pEvent->_eventData, eventData); + JSFunctionHandle eventCallback = JSFunctionHandle::New(getIsolate()->getV8Isolate(),pQueue->_eventCallback); + eventCallback->Call(getIsolate()->getV8Isolate()->GetCurrentContext(), getIsolate()->getGlobal(), eventData.size(), eventData.data()); return true; } return false; diff --git a/src/js/JSFileDescriptorManager.cpp b/src/js/JSFileDescriptorManager.cpp index dcf1cbe2e4..822f804137 100644 --- a/src/js/JSFileDescriptorManager.cpp +++ b/src/js/JSFileDescriptorManager.cpp @@ -38,10 +38,10 @@ JSFileDescriptorManager::~JSFileDescriptorManager() { } -void JSFileDescriptorManager::addFileDescriptor(int fd, v8::Handle ioHandler, int events) +void JSFileDescriptorManager::addFileDescriptor(v8::Isolate* isolate, int fd, v8::Handle ioHandler, int events) { OSS::mutex_critic_sec_lock lock(_descriptorsMutex); - _descriptors[fd] = JSFileDescriptor::Ptr(new JSFileDescriptor(ioHandler, fd, events)); + _descriptors[fd] = JSFileDescriptor::Ptr(new JSFileDescriptor(isolate, ioHandler, fd, events)); } bool JSFileDescriptorManager::removeFileDescriptor(int fd) @@ -75,7 +75,7 @@ void JSFileDescriptorManager::appendDescriptors(Descriptors& descriptors) } } -bool JSFileDescriptorManager::signalIO(pollfd pfd) +bool JSFileDescriptorManager::signalIO(v8::Isolate* isolate, pollfd pfd) { _descriptorsMutex.lock(); DescriptorMap::iterator iter = _descriptors.find(pfd.fd); @@ -85,7 +85,7 @@ bool JSFileDescriptorManager::signalIO(pollfd pfd) // unlock the mutex prior to calling signalIO for it may call our other // functions that would attempt to lock the mutex resulting to a deadlock _descriptorsMutex.unlock(); - pFD->signalIO(pfd); + pFD->signalIO(isolate, pfd); return true; } _descriptorsMutex.unlock(); @@ -94,24 +94,24 @@ bool JSFileDescriptorManager::signalIO(pollfd pfd) JS_METHOD_IMPL(JSFileDescriptorManager::monitor_descriptor) { - js_enter_scope(); + js_method_enter_scope(); js_method_declare_isolate(pIsolate); - js_method_arg_declare_uint32(fd, 0); + js_method_declare_uint32(fd, 0); js_method_arg_assert_function(1); - pIsolate->eventLoop()->fdManager().addFileDescriptor(fd, js_method_arg(1), POLLIN); + pIsolate->eventLoop()->fdManager().addFileDescriptor(js_method_isolate(), fd, js_method_arg(1), POLLIN); pIsolate->eventLoop()->wakeup(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(JSFileDescriptorManager::unmonitor_descriptor) { - js_enter_scope(); + js_method_enter_scope(); js_method_declare_isolate(pIsolate); - js_method_arg_declare_uint32(fd, 0); + js_method_declare_uint32(fd, 0); js_method_arg_assert_function(1); pIsolate->eventLoop()->fdManager().removeFileDescriptor(fd); pIsolate->eventLoop()->wakeup(); - return JSUndefined(); + js_method_set_return_undefined(); } diff --git a/src/js/JSInterIsolateCallManager.cpp b/src/js/JSInterIsolateCallManager.cpp index 0a46360ebb..1d82ce7d56 100644 --- a/src/js/JSInterIsolateCallManager.cpp +++ b/src/js/JSInterIsolateCallManager.cpp @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. // +#include "OSS/JS/JSUtil.h" #include "OSS/JS/JSInterIsolateCallManager.h" #include "OSS/JS/JSIsolate.h" #include "OSS/JS/JSEventLoop.h" @@ -62,8 +63,7 @@ bool JSInterIsolateCallManager::doOneWork() { return false; } - - js_enter_scope(); + v8::HandleScope _scope_(getIsolate()->getV8Isolate()); JSLocalObjectHandle pUserData = getIsolate()->wrapExternalPointer(pCall->getUserData()); JSValueHandle request = getIsolate()->parseJSON(pCall->json()); JSArgumentVector jsonArg; @@ -73,15 +73,19 @@ bool JSInterIsolateCallManager::doOneWork() // Check if this is a callback notification // if (pCall->_cb) { - (*pCall->_cb)->Call(getGlobal(), jsonArg.size(), jsonArg.data()); + JSFunctionHandle cb = JSFunctionHandle::New(getIsolate()->getV8Isolate(),*pCall->_cb); + cb->Call(getIsolate()->getV8Isolate()->GetCurrentContext(), + getIsolate()->getGlobal(), + jsonArg.size(), + jsonArg.data()); pCall->setValue("{}"); - pCall->_cb->Dispose(); + pCall->_cb->Reset(); delete pCall->_cb; pCall->_cb = 0; return true; } - if (_handler.empty()) + if (_handler.IsEmpty()) { // // return true here so that the event loop knows we processed something @@ -90,13 +94,24 @@ bool JSInterIsolateCallManager::doOneWork() return true; } + JSFunctionHandle handler = JSFunctionHandle::New(getIsolate()->getV8Isolate(),_handler); + + v8::MaybeLocal maybeResult = handler->Call(getIsolate()->getV8Isolate()->GetCurrentContext(), + getIsolate()->getGlobal(), + jsonArg.size(), + jsonArg.data()); + + if( maybeResult.IsEmpty() ) + { + return false; + } - JSValueHandle result = _handler.value()->Call(getGlobal(), jsonArg.size(), jsonArg.data()); + JSValueHandle result = maybeResult.ToLocalChecked(); std::string value; - if (!result.IsEmpty() && result->IsString()) + if( result->IsString()) { - value = js_handle_as_std_string(result); + value = string_from_js_string( getIsolate()->getV8Isolate(), JSStringHandle::Cast( result ) ); } pCall->setValue(value); return true; diff --git a/src/js/JSIsolate.cpp b/src/js/JSIsolate.cpp index a17ad238a9..048243b6d1 100644 --- a/src/js/JSIsolate.cpp +++ b/src/js/JSIsolate.cpp @@ -92,18 +92,19 @@ void JSIsolate::dispose() void JSIsolate::internal_run() { - _pIsolate = v8::Isolate::New(); + v8::Isolate::CreateParams params; + _pIsolate = v8::Isolate::New(params); v8::Isolate::Scope global_scope(_pIsolate); _threadId = pthread_self(); JSIsolateManager::instance().registerIsolate(shared_from_this()); - v8::HandleScope handle_scope; + v8::HandleScope handle_scope(_pIsolate); - v8::Handle global = v8::ObjectTemplate::New(); - _globalTemplate = v8::Persistent::New(global); + JSObjectTemplateHandle global = v8::ObjectTemplate::New(_pIsolate); + _globalTemplate = JSCopyablePersistentObjectTemplateHandle(_pIsolate, global); - v8::Handle objectTemplate = v8::ObjectTemplate::New(); + JSObjectTemplateHandle objectTemplate = v8::ObjectTemplate::New(_pIsolate); objectTemplate->SetInternalFieldCount(1); - _objectTemplate = v8::Persistent::New(objectTemplate); + _objectTemplate = JSCopyablePersistentObjectTemplateHandle(_pIsolate, objectTemplate); // // Set the thread id and update the manager @@ -114,8 +115,8 @@ void JSIsolate::internal_run() // Initialize global and assign it to the context // JSIsolateManager::instance().modulesMutex().lock(); - JSIsolateManager::instance().initGlobalExports(global); - _pModuleManager->initGlobalExports(global); + JSIsolateManager::instance().initGlobalExports(_pIsolate,global); + _pModuleManager->initGlobalExports(_pIsolate,global); JSIsolateManager::instance().modulesMutex().unlock(); if (isRoot()) @@ -123,48 +124,51 @@ void JSIsolate::internal_run() _pModuleManager->setMainScript(_script); } - v8::Handle context = v8::Context::New(0, global); - _context = v8::Persistent::New(context); + v8::Handle context = v8::Context::New(_pIsolate, 0, global); + _context = JSCopyablePersistentContextHandle(_pIsolate, context); v8::Context::Scope context_scope(context); - v8::TryCatch try_catch; + v8::TryCatch try_catch( _pIsolate ); try_catch.SetVerbose(true); JSIsolateManager::instance().modulesMutex().lock(); - if (!_pModuleManager->initialize(try_catch, global)) + if (!_pModuleManager->initialize(_pIsolate, try_catch, global)) { OSS_LOG_ERROR("Unable to initialize module manager"); - report_js_exception(try_catch, true); + report_js_exception(_pIsolate, try_catch, true); return; } JSIsolateManager::instance().modulesMutex().unlock(); - v8::Handle compiledScript ; + v8::MaybeLocal maybeCompiledScript; if (_source.empty()) { - v8::Handle scriptSource = read_file_skip_shebang(OSS::boost_path(_script), true); - compiledScript = v8::Script::Compile(scriptSource, v8::String::New(OSS::boost_path(_script).c_str())); + std::string strScriptSource = read_file_skip_shebang(OSS::boost_path(_script), true); + v8::Handle scriptSource = JSString( _pIsolate, strScriptSource ); + v8::ScriptOrigin scriptOrigin(JSString(_pIsolate, OSS::boost_path(_script) ) ); + maybeCompiledScript = v8::Script::Compile(context, scriptSource, &scriptOrigin ); } else { std::ostringstream strm; strm << "try { " << _source << " } catch(e) {console.printStackTrace(e); _exit(-1); } ;async.processEvents();"; - v8::Handle scriptSource = JSString(strm.str()); - compiledScript = v8::Script::Compile(scriptSource); + v8::Handle scriptSource = JSString( _pIsolate, strm.str()); + maybeCompiledScript = v8::Script::Compile(context, scriptSource); } - if (compiledScript.IsEmpty()) + if (maybeCompiledScript.IsEmpty()) { OSS_LOG_ERROR("Unable to compile script"); - report_js_exception(try_catch, true); + report_js_exception(_pIsolate, try_catch, true); _exitValue = -1; return; } - - v8::Handle result = compiledScript->Run(); + v8::Handle compiledScript = maybeCompiledScript.ToLocalChecked(); + + v8::MaybeLocal result = compiledScript->Run( context ); if (result.IsEmpty()) { OSS_LOG_ERROR("Unable to run script"); - report_js_exception(try_catch, true); + report_js_exception(_pIsolate, try_catch, true); _exitValue = -1; return; } @@ -273,21 +277,23 @@ JSPluginManager* JSIsolate::getPluginManager() JSObjectHandle JSIsolate::getGlobal() { - return _context.value()->Global(); + v8::Handle context = v8::Handle::New( _pIsolate, _context ); + return context->Global(); } JSValueHandle JSIsolate::parseJSON(const std::string& json) { - js_enter_scope(); - v8::Local JSON = getGlobal()->Get(JSLiteral("JSON"))->ToObject(); - v8::Handle parseFunc = JSON->Get(JSLiteral("parse")); - v8::Handle parse = v8::Handle::Cast(parseFunc); + v8::HandleScope scope(_pIsolate); + JSContextHandle context = v8::Handle::New( _pIsolate, _context ); + JSObjectHandle JSON = JSObjectHandle::Cast( getGlobal()->Get(context,JSString(_pIsolate,"JSON")).ToLocalChecked() ); + JSValueHandle parseFunc = JSON->Get(context,JSString(_pIsolate,"parse")).ToLocalChecked(); + JSFunctionHandle parse = JSFunctionHandle::Cast(parseFunc); - JSValueHandle val = JSString(json); + JSValueHandle val = JSString(_pIsolate,json); JSArgumentVector args; args.push_back(val); - return parse->Call(getGlobal(), args.size(), args.data()); + return parse->Call(context, getGlobal(), args.size(), args.data()).ToLocalChecked(); } void JSIsolate::join() @@ -302,8 +308,10 @@ void JSIsolate::join() JSLocalObjectHandle JSIsolate::wrapExternalPointer(void* ptr) { - JSLocalObjectHandle pObject = _objectTemplate.value()->NewInstance(); - pObject->SetInternalField(0, JSExternal(ptr)); + JSContextHandle context = v8::Handle::New( _pIsolate, _context ); + JSObjectTemplateHandle objectTemplate = JSObjectTemplateHandle::New( _pIsolate, _objectTemplate ); + JSLocalObjectHandle pObject = objectTemplate->NewInstance(context).ToLocalChecked(); + pObject->SetInternalField(0, JSExternal(_pIsolate,ptr)); return pObject; } diff --git a/src/js/JSIsolateManager.cpp b/src/js/JSIsolateManager.cpp index 60a3fa022b..a8af4c9a9f 100644 --- a/src/js/JSIsolateManager.cpp +++ b/src/js/JSIsolateManager.cpp @@ -37,15 +37,18 @@ namespace JS { // static void V8ErrorMessageCallback(v8::Handle message, v8::Handle data) { - v8::HandleScope handle_scope; + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local context = isolate->GetCurrentContext(); + + v8::HandleScope scope(isolate); - if (message->GetSourceLine()->IsString()) + if (message->GetSourceLine(context).ToLocalChecked()->IsString()) { std::string error = + "Javascript error on line : " - + string_from_js_string(message->GetSourceLine()); + + string_from_js_string(isolate, message->GetSourceLine(context).ToLocalChecked()); OSS::log_error(error); - OSS::log_error(get_stack_trace(message, 1024)); + OSS::log_error(get_stack_trace(isolate, message, 1024)); } } @@ -59,17 +62,18 @@ JSIsolateManager::JSIsolateManager() { if (v8::V8::Initialize()) { + // + // Create the root isolate + // + _rootIsolate = JSIsolate::Ptr(new JSIsolate(0)); + // // Set the external heap to 20mb before attempting to garbage collect // - v8::V8::AdjustAmountOfExternalAllocatedMemory(1024 * 1024 * 20); - v8::V8::AddMessageListener(V8ErrorMessageCallback); + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(1024 * 1024 * 20); + v8::Isolate::GetCurrent()->AddMessageListener(V8ErrorMessageCallback); } - // - // Create the root isolate - // - _rootIsolate = JSIsolate::Ptr(new JSIsolate(0)); } JSIsolateManager::~JSIsolateManager() @@ -151,11 +155,11 @@ intptr_t JSIsolateManager::getExternalData(const std::string& name) const return iter->second; } -void JSIsolateManager::initGlobalExports(JSObjectTemplateHandle& global) +void JSIsolateManager::initGlobalExports(v8::Isolate* isolate, JSObjectTemplateHandle& global) { for(GlobalExports::iterator iter = _exports.begin(); iter != _exports.end(); iter++) { - global->Set(v8::String::New(iter->first.c_str()), v8::FunctionTemplate::New(iter->second)); + global->Set(JSString(isolate,iter->first), v8::FunctionTemplate::New(isolate,iter->second)); } for (GlobalExportVector::iterator iter = _exportHandlers.begin(); iter != _exportHandlers.end(); iter++) diff --git a/src/js/JSModule.cpp b/src/js/JSModule.cpp index e987d1c8d4..524f23bc6c 100644 --- a/src/js/JSModule.cpp +++ b/src/js/JSModule.cpp @@ -36,39 +36,50 @@ namespace JS { boost::filesystem::path JSModule::_mainScript; -static JSModule*get_current_module_manager() +static JSModule* get_current_module_manager() { return JSIsolateManager::instance().getIsolate()->getModuleManager(); } -static v8::Handle js_include(const v8::Arguments& args) +static JS_METHOD_IMPL(js_include) { - v8::HandleScope scope; - v8::TryCatch try_catch; - try_catch.SetVerbose(true); + js_method_enter_scope(); + js_method_try_catch(); + _try_catch_.SetVerbose(true); - for (int i = 0; i < args.Length(); i++) + for (int i = 0; i < _args_.Length(); i++) { - std::string fileName = string_from_js_value(args[i]); + std::string fileName = string_from_js_value(js_method_isolate(), _args_[i]); if (boost::filesystem::exists(fileName)) { - v8::Handle script = read_file(fileName); - v8::Handle compiled = v8::Script::Compile(script); - v8::Handle result = compiled->Run(); - if (result.IsEmpty()) + v8::Handle script = js_method_string( read_file(fileName) ); + v8::MaybeLocal maybeCompiled = v8::Script::Compile(js_method_context(),script); + if( maybeCompiled.IsEmpty() ) { // The TryCatch above is still in effect and will have caught the error. - report_js_exception(try_catch, true); - return v8::Undefined(); + report_js_exception(js_method_isolate(), _try_catch_, true); + js_method_set_return_undefined(); + return; } - return result; + v8::Handle compiled = maybeCompiled.ToLocalChecked(); + v8::MaybeLocal maybeResult = compiled->Run(js_method_context()); + if (maybeResult.IsEmpty()) + { + // The TryCatch above is still in effect and will have caught the error. + report_js_exception(js_method_isolate(), _try_catch_, true); + js_method_set_return_undefined(); + return; + } + v8::Handle result = maybeResult.ToLocalChecked(); + js_method_set_return_handle( result ); + return; } else { OSS_LOG_ERROR("Unable to locate external script " << fileName); } } - return v8::Undefined(); + js_method_set_return_undefined(); } static bool module_path_exists(const std::string& canonicalName, std::string& absolutePath) @@ -169,10 +180,10 @@ static bool module_path_exists(const std::string& canonicalName, std::string& ab JS_METHOD_IMPL(__add_module_directory) { - v8::HandleScope scope; - js_method_arg_declare_string(path, 0); + js_method_enter_scope(); + js_method_declare_string(path, 0); get_current_module_manager()->setModulesDir(path); - return JSUndefined(); + js_method_set_return_undefined(); } static std::string get_plugin_canonical_file_name(const std::string& fileName) @@ -266,151 +277,182 @@ static std::string get_module_canonical_file_name(const std::string& fileName) return get_plugin_canonical_file_name(fileName); } -static v8::Handle js_get_module_cononical_file_name(const v8::Arguments& args) +static JS_METHOD_IMPL(js_get_module_cononical_file_name) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; - v8::TryCatch try_catch; - try_catch.SetVerbose(true); - std::string fileName = string_from_js_value(args[0]); + js_method_enter_scope(); + js_method_try_catch(); + _try_catch_.SetVerbose(true); + std::string fileName = string_from_js_value(js_method_isolate(), _args_[0]); std::string canonical = get_module_canonical_file_name(fileName); if (canonical.empty()) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - return v8::String::New(canonical.c_str()); + js_method_set_return_string(canonical.c_str()); } -static v8::Handle js_load_plugin(const v8::Arguments& args) +static JS_METHOD_IMPL(js_load_plugin) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; - v8::TryCatch try_catch; - try_catch.SetVerbose(true); - std::string fileName = string_from_js_value(args[0]); + js_method_enter_scope(); + js_method_try_catch(); + _try_catch_.SetVerbose(true); + std::string fileName = string_from_js_value(js_method_isolate(), _args_[0]); js_method_declare_isolate(pIsolate); JSPlugin* pPlugin = pIsolate->getPluginManager()->loadPlugin(fileName); if (!pPlugin) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } std::string exportFunc; - if (pPlugin->initExportFunc(exportFunc)) + if (pPlugin->initExportFunc(js_method_isolate(), exportFunc)) { - v8::Handle func_name = v8::String::New(exportFunc.c_str()); - return js_get_global()->Get(func_name); + JSStringHandle func_name = js_method_string(exportFunc.c_str()); + js_method_set_return_handle(js_method_global()->Get(js_method_context(),func_name).ToLocalChecked()); + return; } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle js_get_module_script(const v8::Arguments& args) +static JS_METHOD_IMPL(js_get_module_script) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; - v8::TryCatch try_catch; - try_catch.SetVerbose(true); + js_method_enter_scope(); + js_method_try_catch(); + _try_catch_.SetVerbose(true); - std::string fileName = string_from_js_value(args[0]); + std::string fileName = string_from_js_value(js_method_isolate(), _args_[0]); JSModule::InternalModules& modules = get_current_module_manager()->getInternalModules(); JSModule::InternalModules::iterator iter = modules.find(fileName); if (iter != modules.end()) { - return v8::Handle(v8::String::New(iter->second.script.c_str())); + js_method_set_return_string(iter->second.script); + return; } if (boost::filesystem::exists(fileName)) { - return read_file(fileName); + js_method_set_return_string(read_file(fileName)); + return; } else { OSS_LOG_ERROR("Unable to locate module " << fileName); } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle js_compile(const v8::Arguments& args) +static JS_METHOD_IMPL(js_compile) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; - v8::TryCatch try_catch; - try_catch.SetVerbose(true); + js_method_enter_scope(); + js_method_try_catch(); + _try_catch_.SetVerbose(true); - v8::Handle script = v8::Handle::Cast(args[0]); - v8::Handle compiled = v8::Script::Compile(script, args[1]); - - v8::Handle result = compiled->Run(); - if (result.IsEmpty()) + v8::Handle script = v8::Handle::Cast(_args_[0]); + v8::ScriptOrigin name(JSStringHandle::Cast(_args_[1])); + v8::MaybeLocal maybeCompiled = v8::Script::Compile(js_method_context(),script, &name); + if( maybeCompiled.IsEmpty() ) + { + // The TryCatch above is still in effect and will have caught the error. + report_js_exception(js_method_isolate(), _try_catch_, true); + js_method_set_return_undefined(); + return; + } + v8::Handle compiled = maybeCompiled.ToLocalChecked(); + v8::MaybeLocal maybeResult = compiled->Run(js_method_context()); + if (maybeResult.IsEmpty()) { // The TryCatch above is still in effect and will have caught the error. - report_js_exception(try_catch, true); - return v8::Undefined(); + report_js_exception(js_method_isolate(), _try_catch_, true); + js_method_set_return_undefined(); + return; } - return result; + v8::Handle result = maybeResult.ToLocalChecked(); + js_method_set_return_handle( result ); } -static v8::Handle js_compile_module(const v8::Arguments& args) +static JS_METHOD_IMPL(js_compile_module) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; - v8::TryCatch try_catch; - try_catch.SetVerbose(true); + js_method_enter_scope(); + js_method_try_catch(); + _try_catch_.SetVerbose(true); std::ostringstream strm; strm << "( function(module, exports) {"; strm << "\"use-strict\";"; strm << "try {"; - strm << string_from_js_value(args[0]); + strm << string_from_js_value(js_method_isolate(), _args_[0]); strm << "} catch(e) { e.printStackTrace(); }"; strm << "});"; - v8::Handle script(v8::String::New(strm.str().c_str())); - v8::Handle compiled = v8::Script::New(script, args[1]); - - std::string fileName = *v8::String::Utf8Value(args[1]); + JSStringHandle script = js_method_string(strm.str()); + //v8::Handle compiled = v8::Script::New(script, name); // changed in V8 3.25 + v8::ScriptOrigin name(JSStringHandle::Cast(_args_[1])); + v8::MaybeLocal maybeCompiled = v8::Script::Compile(js_method_context(),script, &name); + if( maybeCompiled.IsEmpty() ) + { + // The TryCatch above is still in effect and will have caught the error. + report_js_exception(js_method_isolate(), _try_catch_, true); + js_method_set_return_undefined(); + return; + } + v8::Handle compiled = maybeCompiled.ToLocalChecked(); + + std::string fileName = *v8::String::Utf8Value(js_method_isolate(),_args_[1]); boost::filesystem::path path(fileName.c_str()); boost::filesystem::path parent_path = path.parent_path(); boost::filesystem::path current_path = boost::filesystem::current_path(); - v8::Handle result = compiled->Run(); - - if (result.IsEmpty()) + v8::MaybeLocal maybeResult = compiled->Run(js_method_context()); + if (maybeResult.IsEmpty()) { // The TryCatch above is still in effect and will have caught the error. - report_js_exception(try_catch, true); - return v8::Undefined(); + report_js_exception(js_method_isolate(), _try_catch_, true); + js_method_set_return_undefined(); + return; } - return result; + v8::Handle result = maybeResult.ToLocalChecked(); + js_method_set_return_handle( result ); } JS_METHOD_IMPL(js_lock_isolate) { JSIsolateManager::instance().modulesMutex().lock(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(js_unlock_isolate) { JSIsolateManager::instance().modulesMutex().unlock(); - return JSUndefined(); + js_method_set_return_undefined(); } JSModule::JSModule(JSIsolate* pIsolate) : @@ -423,7 +465,7 @@ JSModule::~JSModule() { } -bool JSModule::initialize(v8::TryCatch& try_catch, v8::Handle& global) +bool JSModule::initialize(v8::Isolate* isolate, v8::TryCatch& try_catch, v8::Handle& global) { // // Register the helpers @@ -434,7 +476,7 @@ bool JSModule::initialize(v8::TryCatch& try_catch, v8::Handle& global) +bool JSModule::initGlobalExports(v8::Isolate* isolate, v8::Handle& global) { - global->Set(v8::String::New("__include"), v8::FunctionTemplate::New(js_include)); - global->Set(v8::String::New("__compile"), v8::FunctionTemplate::New(js_compile)); - global->Set(v8::String::New("__compile_module"), v8::FunctionTemplate::New(js_compile_module)); - global->Set(v8::String::New("__get_module_script"), v8::FunctionTemplate::New(js_get_module_script)); - global->Set(v8::String::New("__get_module_cononical_file_name"), v8::FunctionTemplate::New(js_get_module_cononical_file_name)); - global->Set(v8::String::New("__load_plugin"), v8::FunctionTemplate::New(js_load_plugin)); - global->Set(v8::String::New("__current_path"), v8::FunctionTemplate::New(__current_path)); - global->Set(v8::String::New("__parent_path"), v8::FunctionTemplate::New(__parent_path)); - global->Set(v8::String::New("__chdir"), v8::FunctionTemplate::New(__chdir)); - global->Set(v8::String::New("__lock_isolate"), v8::FunctionTemplate::New(js_lock_isolate)); - global->Set(v8::String::New("__unlock_isolate"), v8::FunctionTemplate::New(js_unlock_isolate)); - global->Set(v8::String::New("__add_module_directory"), v8::FunctionTemplate::New(__add_module_directory)); + global->Set(JSString(isolate,"__include"), JSFunctionTemplate(isolate,js_include)); + global->Set(JSString(isolate,"__compile"), JSFunctionTemplate(isolate,js_compile)); + global->Set(JSString(isolate,"__compile_module"), JSFunctionTemplate(isolate,js_compile_module)); + global->Set(JSString(isolate,"__get_module_script"), JSFunctionTemplate(isolate,js_get_module_script)); + global->Set(JSString(isolate,"__get_module_cononical_file_name"), JSFunctionTemplate(isolate,js_get_module_cononical_file_name)); + global->Set(JSString(isolate,"__load_plugin"), JSFunctionTemplate(isolate,js_load_plugin)); + global->Set(JSString(isolate,"__current_path"), JSFunctionTemplate(isolate,__current_path)); + global->Set(JSString(isolate,"__parent_path"), JSFunctionTemplate(isolate,__parent_path)); + global->Set(JSString(isolate,"__chdir"), JSFunctionTemplate(isolate,__chdir)); + global->Set(JSString(isolate,"__lock_isolate"), JSFunctionTemplate(isolate,js_lock_isolate)); + global->Set(JSString(isolate,"__unlock_isolate"), JSFunctionTemplate(isolate,js_unlock_isolate)); + global->Set(JSString(isolate,"__add_module_directory"), JSFunctionTemplate(isolate,__add_module_directory)); return true; } -bool JSModule::compileModuleHelpers(v8::TryCatch& try_catch, v8::Handle& global) +bool JSModule::compileModuleHelpers(v8::Isolate* isolate, v8::TryCatch& try_catch, v8::Handle& global) { + v8::Local context = isolate->GetCurrentContext(); + for (ModuleHelpers::iterator iter = _moduleHelpers.begin(); iter != _moduleHelpers.end(); iter++) { - v8::Handle script(v8::String::New(iter->script.c_str())); - v8::Handle name(v8::String::New(iter->name.c_str())); - v8::Handle compiled = v8::Script::Compile(script, name); - v8::Handle result = compiled->Run(); - if (result.IsEmpty()) + v8::Handle script(JSString(isolate,iter->script)); + v8::ScriptOrigin name(JSString(isolate,iter->name)); + v8::MaybeLocal maybeCompiled = v8::Script::Compile(context,script, &name); + if( maybeCompiled.IsEmpty() ) { OSS_LOG_ERROR("JSModule::compileModuleHelpers is unable to compile " << iter->name); // The TryCatch above is still in effect and will have caught the error. - report_js_exception(try_catch, true); + report_js_exception(isolate, try_catch, true); + return false; + } + v8::Handle compiled = maybeCompiled.ToLocalChecked(); + + v8::MaybeLocal maybeResult = compiled->Run(context); + if (maybeResult.IsEmpty()) + { + OSS_LOG_ERROR("JSModule::compileModuleHelpers is unable to run " << iter->name); + // The TryCatch above is still in effect and will have caught the error. + report_js_exception(isolate, try_catch, true); return false; } } diff --git a/src/js/JSObjectWrap.cpp b/src/js/JSObjectWrap.cpp index 1297f13a44..d800b64456 100644 --- a/src/js/JSObjectWrap.cpp +++ b/src/js/JSObjectWrap.cpp @@ -43,11 +43,13 @@ JSObjectWrap::~JSObjectWrap ( ) if (!handle_.IsEmpty()) { - assert(handle_.IsNearDeath()); + //assert(handle_.IsNearDeath()); // Removed in V8 7.5 API handle_.ClearWeak(); - handle_->SetInternalField(0, v8::Undefined()); - handle_.Dispose(); - handle_.Clear(); + v8::Local obj = v8::Local::New(_pIsolate->getV8Isolate(),handle_); + obj->SetInternalField(0, v8::Undefined(_pIsolate->getV8Isolate())); + //handle_.Dispose(); Removed V8 3.24 API, use Reset + //handle_.Clear(); Removed V8 3.24 API, use Reset + handle_.Reset(); } } @@ -55,16 +57,16 @@ void JSObjectWrap::Wrap (v8::Handle handle) { assert(handle_.IsEmpty()); assert(handle->InternalFieldCount() > 0); - handle_ = v8::Persistent::New(handle); - handle_->SetPointerInInternalField(0, this); + handle->SetAlignedPointerInInternalField(0, this); + handle_ = v8::Persistent>(_pIsolate->getV8Isolate(),handle); MakeWeak(); } void JSObjectWrap::MakeWeak (void) { - handle_.MakeWeak(this, WeakCallback); - handle_.MarkIndependent(); + handle_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); + //handle_.MarkIndependent(); // Removed V8 7.6 API } /* Ref() marks the object as being attached to an event loop. @@ -99,13 +101,13 @@ void JSObjectWrap::Unref() } -void JSObjectWrap::WeakCallback (v8::Persistent value, void *data) +void JSObjectWrap::WeakCallback(const v8::WeakCallbackInfo& data) { - JSObjectWrap *obj = static_cast(data); - assert(value == obj->handle_); - assert(!obj->refs_); - assert(value.IsNearDeath()); - delete obj; + JSObjectWrap* objectWrap = data.GetParameter(); + //assert(value == objectWrap->handle_); + assert(!objectWrap->refs_); + //assert(value.IsNearDeath()); // Removed in V8 7.5 API + delete objectWrap; } diff --git a/src/js/JSUtil.cpp b/src/js/JSUtil.cpp index ad00856345..9e58cee32b 100644 --- a/src/js/JSUtil.cpp +++ b/src/js/JSUtil.cpp @@ -32,19 +32,19 @@ namespace JS { -std::string string_from_js_string(v8::Handle str) +std::string string_from_js_string(v8::Isolate* isolate, v8::Handle str) { if (!str->IsString()) return ""; - v8::String::Utf8Value value(str); + v8::String::Utf8Value value(isolate,str); return *value; } -std::string string_from_js_value(const v8::Handle& str) +std::string string_from_js_value(v8::Isolate* isolate, const v8::Handle& str) { if (!str->IsString()) return ""; - v8::String::Utf8Value value(str); + v8::String::Utf8Value value(isolate,str); return *value; } @@ -53,13 +53,13 @@ const char* cstring_from_js_string(const v8::String::Utf8Value& value) return *value ? *value : ""; } -void report_js_exception(v8::TryCatch &try_catch, bool show_line) +void report_js_exception(v8::Isolate* isolate, v8::TryCatch &try_catch, bool show_line) { using namespace v8; Handle message = try_catch.Message(); - v8::String::Utf8Value error(try_catch.Exception()); + v8::String::Utf8Value error(isolate,try_catch.Exception()); if (error.length() > 0) { @@ -81,14 +81,14 @@ void report_js_exception(v8::TryCatch &try_catch, bool show_line) if (show_line && !message.IsEmpty()) { // Print (filename):(line number): (message). - String::Utf8Value filename(message->GetScriptResourceName()); + String::Utf8Value filename(isolate,message->GetScriptResourceName()); const char* filename_string = cstring_from_js_string(filename); - int linenum = message->GetLineNumber(); + int linenum = message->GetLineNumber(isolate->GetCurrentContext()).ToChecked(); //fprintf(stderr, "%s:%i\n", filename_string, linenum); errorMsg << filename_string << ":" << linenum << std::endl; // Print line of source code. - String::Utf8Value sourceline(message->GetSourceLine()); + String::Utf8Value sourceline(isolate,message->GetSourceLine(isolate->GetCurrentContext()).ToLocalChecked()); const char* sourceline_string = cstring_from_js_string(sourceline); // HACK HACK HACK @@ -114,12 +114,12 @@ void report_js_exception(v8::TryCatch &try_catch, bool show_line) //fprintf(stderr, "%s\n", sourceline_string + offset); errorMsg << sourceline_string + offset << std::endl; // Print wavy underline (GetUnderline is deprecated). - int start = message->GetStartColumn(); + int start = message->GetStartColumn(isolate->GetCurrentContext()).ToChecked(); for (int i = offset; i < start; i++) { errorMsg << " "; } - int end = message->GetEndColumn(); + int end = message->GetEndColumn(isolate->GetCurrentContext()).ToChecked(); for (int i = start; i < end; i++) { errorMsg << "^"; @@ -127,7 +127,7 @@ void report_js_exception(v8::TryCatch &try_catch, bool show_line) errorMsg << std::endl; } - String::Utf8Value trace(try_catch.StackTrace()); + String::Utf8Value trace(isolate,try_catch.StackTrace(isolate->GetCurrentContext()).ToLocalChecked()); if (trace.length() > 0) { @@ -142,101 +142,108 @@ void report_js_exception(v8::TryCatch &try_catch, bool show_line) } - -v8::Handle log_info_callback(const v8::Arguments& args) +JS_GLOBAL_FUNCTION_IMPL(log_info_callback) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - if (args.Length() == 2) + if (_args_.Length() == 2) { - v8::HandleScope scope; - v8::Handle arg0 = args[0]; - v8::String::Utf8Value value0(arg0); + js_method_enter_scope(); + v8::Handle arg0 = _args_[0]; + v8::String::Utf8Value value0(js_method_isolate(),arg0); - v8::Handle arg1 = args[1]; - v8::String::Utf8Value value1(arg1); + v8::Handle arg1 = _args_[1]; + v8::String::Utf8Value value1(js_method_isolate(),arg1); std::ostringstream msg; msg << *value0 << " " << *value1; OSS::log_information(msg.str()); } else { - v8::HandleScope scope; - v8::Handle arg = args[0]; - v8::String::Utf8Value value(arg); + js_method_enter_scope(); + v8::Handle arg = _args_[0]; + v8::String::Utf8Value value(js_method_isolate(),arg); std::ostringstream msg; msg << *value; OSS::log_information(msg.str()); } - return v8::Undefined(); + js_method_set_return_undefined(); } -v8::Handle log_debug_callback(const v8::Arguments& args) +JS_GLOBAL_FUNCTION_IMPL(log_debug_callback) { - if (args.Length() < 1) - return v8::Undefined(); - - if (args.Length() == 2) + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + if (_args_.Length() == 2) { - v8::HandleScope scope; - v8::Handle arg0 = args[0]; - v8::String::Utf8Value value0(arg0); + js_method_enter_scope(); + v8::Handle arg0 = _args_[0]; + v8::String::Utf8Value value0(js_method_isolate(),arg0); - v8::Handle arg1 = args[1]; - v8::String::Utf8Value value1(arg1); + v8::Handle arg1 = _args_[1]; + v8::String::Utf8Value value1(js_method_isolate(),arg1); std::ostringstream msg; msg << *value0 << " " << *value1; OSS::log_debug(msg.str()); } else { - v8::HandleScope scope; - v8::Handle arg = args[0]; - v8::String::Utf8Value value(arg); + js_method_enter_scope(); + v8::Handle arg = _args_[0]; + v8::String::Utf8Value value(js_method_isolate(),arg); std::ostringstream msg; msg << *value; OSS::log_debug(msg.str()); } - return v8::Undefined(); + js_method_set_return_undefined(); } -v8::Handle log_error_callback(const v8::Arguments& args) +JS_GLOBAL_FUNCTION_IMPL(log_error_callback) { - if (args.Length() < 1) - return v8::Undefined(); - - if (args.Length() == 2) + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + if (_args_.Length() == 2) { - v8::HandleScope scope; - v8::Handle arg0 = args[0]; - v8::String::Utf8Value value0(arg0); + js_method_enter_scope(); + v8::Handle arg0 = _args_[0]; + v8::String::Utf8Value value0(js_method_isolate(),arg0); - v8::Handle arg1 = args[1]; - v8::String::Utf8Value value1(arg1); + v8::Handle arg1 =_args_[1]; + v8::String::Utf8Value value1(js_method_isolate(),arg1); std::ostringstream msg; msg << *value0 << "JavaScript Error: " << *value1; OSS::log_error(msg.str()); } else { - v8::HandleScope scope; - v8::Handle arg = args[0]; - v8::String::Utf8Value value(arg); + js_method_enter_scope(); + v8::Handle arg = _args_[0]; + v8::String::Utf8Value value(js_method_isolate(),arg); std::ostringstream msg; msg << "JavaScript Error: " << *value; OSS::log_error(msg.str()); } - return v8::Undefined(); + + js_method_set_return_undefined(); } // Reads a file into a v8 string. -v8::Handle read_file(const std::string& name) +std::string read_file(const std::string& name) { FILE* file = fopen(name.c_str(), "rb"); - if (file == NULL) return v8::Handle(); + if (file == NULL) return ""; fseek(file, 0, SEEK_END); int size = ftell(file); @@ -254,19 +261,19 @@ v8::Handle read_file(const std::string& name) // Check if it starts with a shebang // - v8::Handle result = v8::String::New(chars, size); + std::string result( chars, size); delete[] chars; return result; } -v8::Handle read_file_skip_shebang(const std::string& name, bool hasCommonJS) +std::string read_file_skip_shebang(const std::string& name, bool hasCommonJS) { std::ifstream scriptFile; scriptFile.open(name.c_str()); if (!scriptFile.is_open() || !scriptFile.good()) { - return v8::Handle(); + return ""; } std::ostringstream strm; @@ -286,10 +293,10 @@ v8::Handle read_file_skip_shebang(const std::string& name, bool hasC } if (hasCommonJS) strm << " } catch(e) {console.printStackTrace(e); _exit(-1); } ;async.processEvents();"; - return v8::String::New(strm.str().data(), strm.str().size()); + return strm.str(); } -v8::Handle read_directory(const boost::filesystem::path& directory) +std::string read_directory(const boost::filesystem::path& directory) { std::string data; @@ -317,7 +324,7 @@ v8::Handle read_directory(const boost::filesystem::path& directory) if (file == NULL) { OSS_LOG_ERROR("Google V8 failed to open file " << currentFile); - return v8::Handle(); + return ""; } fseek(file, 0, SEEK_END); @@ -350,37 +357,39 @@ v8::Handle read_directory(const boost::filesystem::path& directory) } } - return v8::String::New(data.c_str(), data.size()); + return data; } -void wrap_external_object(v8::Persistent* pContext, +/* Not used +void wrap_external_object(v8::Isolate* isolate, v8::Persistent* pRequestTemplate, v8::Handle& objectInstance, OSS_HANDLE pObject) { // Fetch the template for creating JavaScript request wrappers. // It only has to be created once, which we do on demand. - v8::Handle templ = *pRequestTemplate; + v8::Handle templ = v8::Handle::New( isolate, *pRequestTemplate); // Set up an exception handler before calling the Process function - objectInstance = templ->NewInstance(); + objectInstance = templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); // Wrap the raw C++ pointer in an External so it can be referenced // from within JavaScript. - v8::Handle request_ptr = v8::External::New(pObject); + v8::Handle request_ptr = v8::External::New(isolate,pObject); // Store the request pointer in the JavaScript wrapper. objectInstance->SetInternalField(0, request_ptr); } +*/ -std::string get_stack_trace(v8::Handle message, uint32_t bufLen) +std::string get_stack_trace(v8::Isolate* isolate, v8::Handle message, uint32_t bufLen) { FILE* fp = ::fmemopen(0, bufLen, "w+"); - message->PrintCurrentStackTrace(fp); + message->PrintCurrentStackTrace(isolate,fp); fseek(fp, 0, SEEK_END); int size = ftell(fp); diff --git a/src/js/modules/async/async.cpp b/src/js/modules/async/async.cpp index 7d665c356f..43f7051fd9 100644 --- a/src/js/modules/async/async.cpp +++ b/src/js/modules/async/async.cpp @@ -32,63 +32,60 @@ #include "OSS/UTL/Semaphore.h" -typedef v8::Persistent PersistentFunction; -typedef std::vector< v8::Persistent > ArgumentVector; - static bool _enableAsync = false; static OSS::Semaphore* _exitSem = 0; static OSS::UInt64 _garbageCollectionFrequency = 30; /// 30 seconds default pthread_t Async::_threadId = 0; -v8::Persistent Async::_externalPointerTemplate; +JSCopyablePersistentObjectTemplateHandle Async::_externalPointerTemplate; -static v8::Handle __call(const v8::Arguments& args) +JS_METHOD_IMPL(__call) { - v8::HandleScope scope; - if (args.Length() != 3 || !args[0]->IsFunction() || !args[1]->IsArray() || !args[2]->IsFunction()) + js_method_enter_scope(); + if (_args_.Length() != 3 || !_args_[0]->IsFunction() || !_args_[1]->IsArray() || !_args_[2]->IsFunction()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } js_method_declare_isolate(pIsolate); - pIsolate->eventLoop()->functionCallback().execute(args[0], args[1], args[2]); + pIsolate->eventLoop()->functionCallback().execute(_args_[0], _args_[1], _args_[2]); _enableAsync = true; - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle __schedule_one_shot_timer(const v8::Arguments& args) +JS_METHOD_IMPL(__schedule_one_shot_timer) { - v8::HandleScope scope; - if (args.Length() < 2 || !args[0]->IsFunction() || !args[1]->IsInt32()) + js_method_enter_scope(); + if (_args_.Length() < 2 || !_args_[0]->IsFunction() || !_args_[1]->IsInt32()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } - int expire = args[1]->ToInt32()->Value(); + int expire = _args_[1]->Int32Value(js_method_context()).ToChecked(); js_method_declare_isolate(pIsolate); int timerId = 0; - if (args.Length() >= 3) + if (_args_.Length() >= 3) { - timerId = pIsolate->eventLoop()->timerManager().scheduleTimer(expire, args[0], args[2]); + timerId = pIsolate->eventLoop()->timerManager().scheduleTimer(expire, _args_[0], _args_[2]); } else { - timerId = pIsolate->eventLoop()->timerManager().scheduleTimer(expire, args[0]); + timerId = pIsolate->eventLoop()->timerManager().scheduleTimer(expire, _args_[0]); } _enableAsync = true; - return v8::Int32::New(timerId); + js_method_set_return_handle(js_method_int32(timerId)); } -static v8::Handle __cancel_one_shot_timer(const v8::Arguments& args) +JS_METHOD_IMPL(__cancel_one_shot_timer) { - v8::HandleScope scope; - if (args.Length() < 1 || !args[0]->IsInt32()) + js_method_enter_scope(); + if (_args_.Length() < 1 || !_args_[0]->IsInt32()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } - int32_t timerId = args[0]->ToInt32()->Value(); + int32_t timerId = _args_[0]->Int32Value(js_method_context()).ToChecked(); Async::clear_timer(timerId); - return v8::Undefined(); + js_method_set_return_undefined(); } void Async::clear_timer(int timerId) @@ -109,21 +106,21 @@ void Async::__wakeup_pipe(OSS::JS::JSIsolate* pIsolate) } } -static v8::Handle __monitor_descriptor(const v8::Arguments& args) +JS_METHOD_IMPL(__monitor_descriptor) { - v8::HandleScope scope; - if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsFunction()) + js_method_enter_scope(); + if (_args_.Length() < 2 || !_args_[0]->IsInt32() || !_args_[1]->IsFunction()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } _enableAsync = true; js_method_declare_isolate(pIsolate); OSS::JS::JSEventLoop* pEventLoop = pIsolate->eventLoop(); - pEventLoop->fdManager().addFileDescriptor(args[0]->ToInt32()->Value(), args[1], POLLIN); + pEventLoop->fdManager().addFileDescriptor(js_method_isolate(), _args_[0]->Int32Value(js_method_context()).ToChecked(), _args_[1], POLLIN); Async::__wakeup_pipe(); - return v8::Undefined(); + js_method_set_return_undefined(); } void Async::unmonitor_fd(const OSS::JS::JSIsolate::Ptr& pIsolate, int fd) { @@ -133,25 +130,25 @@ void Async::unmonitor_fd(const OSS::JS::JSIsolate::Ptr& pIsolate, int fd) } } -static v8::Handle __unmonitor_descriptor(const v8::Arguments& args) +JS_METHOD_IMPL(__unmonitor_descriptor) { - v8::HandleScope scope; - if (args.Length() < 1 || !args[0]->IsInt32()) + js_method_enter_scope(); + if (_args_.Length() < 1 || !_args_[0]->IsInt32()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } js_method_declare_isolate(pIsolate); - int fd = args[0]->ToInt32()->Value(); + int fd = _args_[0]->Int32Value(js_method_context()).ToChecked(); Async::unmonitor_fd(pIsolate, fd); - return v8::Undefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__set_promise_callback) { - js_method_arg_declare_persistent_function(func, 0); + js_method_declare_copyable_persistent_function(func, 0); OSS::JS::JSIsolate::getIsolate()->eventLoop()->interIsolate().setHandler(func); _enableAsync = true; - return JSUndefined(); + js_method_set_return_undefined(); } bool Async::json_execute_promise(OSS::JS::JSIsolate* pIsolate, const OSS::JSON::Object& request, OSS::JSON::Object& reply, uint32_t timeout, void* promiseData) @@ -160,26 +157,26 @@ bool Async::json_execute_promise(OSS::JS::JSIsolate* pIsolate, const OSS::JSON:: } -static v8::Handle __stop_event_loop(const v8::Arguments& args) +JS_METHOD_IMPL(__stop_event_loop) { - v8::HandleScope scope; + js_method_enter_scope(); OSS::JS::JSIsolate::getIsolate()->eventLoop()->terminate(); Async::__wakeup_pipe(); - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle __set_garbage_collection_frequency(const v8::Arguments& args) +JS_METHOD_IMPL(__set_garbage_collection_frequency) { - v8::HandleScope scope; - if (args.Length() == 0 || !args[0]->IsInt32()) + js_method_enter_scope(); + if (_args_.Length() == 0 || !_args_[0]->IsInt32()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } - _garbageCollectionFrequency = args[0]->ToInt32()->Value(); - return v8::Undefined(); + _garbageCollectionFrequency = _args_[0]->Int32Value(js_method_context()).ToChecked(); + js_method_set_return_undefined(); } -static v8::Handle __process_events(const v8::Arguments& args) +JS_METHOD_IMPL(__process_events) { Async::_threadId = pthread_self(); @@ -202,7 +199,7 @@ static v8::Handle __process_events(const v8::Arguments& args) { _exitSem->signal(); } - return v8::Undefined(); + js_method_set_return_undefined(); } JS_EXPORTS_INIT() @@ -223,9 +220,9 @@ JS_EXPORTS_INIT() // // Create the template we use to wrap C++ pointers // - v8::Handle externalObjectTemplate = v8::ObjectTemplate::New(); + JSObjectTemplateHandle externalObjectTemplate = v8::ObjectTemplate::New(js_method_isolate()); externalObjectTemplate->SetInternalFieldCount(1); - Async::_externalPointerTemplate = v8::Persistent::New(externalObjectTemplate); + Async::_externalPointerTemplate = JSCopyablePersistentObjectTemplateHandle(js_method_isolate(), externalObjectTemplate); js_export_finalize(); } diff --git a/src/js/modules/async/queue_object.cpp b/src/js/modules/async/queue_object.cpp index 692842eb81..dbd5887b83 100644 --- a/src/js/modules/async/queue_object.cpp +++ b/src/js/modules/async/queue_object.cpp @@ -46,32 +46,32 @@ QueueObject::QueueObject() : QueueObject::~QueueObject() { - _eventCallback.Dispose(); + _eventCallback.Reset(); getIsolate()->eventLoop()->queueManager().removeQueue(this); Async::__wakeup_pipe(); } JS_CONSTRUCTOR_IMPL(QueueObject) { - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_copyable_persistent_function(handler, 0); QueueObject* pQueue = new QueueObject(); pQueue->_eventCallback = handler; - pQueue->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pQueue->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(QueueObject::enqueue) { - js_method_arg_declare_array(items, 0); - js_method_arg_declare_self(QueueObject, pQueue); + js_method_declare_array(items, 0); + js_method_declare_self(QueueObject, pQueue); Event::Ptr pEvent = Event::Ptr(new QueueObject::Event()); - js_assign_persistent_arg_vector(pEvent->_eventData, _args_[0]); + js_assign_persistent_arg_vector(js_method_isolate(), pEvent->_eventData, _args_[0]); pQueue->_queue.enqueue(pEvent); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(QueueObject::getFd) { - js_method_arg_declare_self(QueueObject, self); - return JSInt32(self->_queue.getFd()); + js_method_declare_self(QueueObject, self); + js_method_set_return_handle(js_method_int32(self->_queue.getFd())); } \ No newline at end of file diff --git a/src/js/modules/buffer/buffer.cpp b/src/js/modules/buffer/buffer.cpp index 6341fd8daa..b575e89f69 100644 --- a/src/js/modules/buffer/buffer.cpp +++ b/src/js/modules/buffer/buffer.cpp @@ -61,132 +61,133 @@ BufferObject::~BufferObject() { } -JSValueHandle BufferObject::createNew(uint32_t size) +JSValueHandle BufferObject::createNew(v8::Isolate* isolate, uint32_t size) { JSValueHandle funcArgs[1]; - funcArgs[0] = JSUInt32(size); - return BufferObject::_constructor->CallAsConstructor(1, funcArgs); + funcArgs[0] = JSUint32(isolate,size); + JSFunctionHandle constructor = JSFunctionHandle::New( isolate, BufferObject::_constructor ); + return constructor->CallAsConstructor(isolate->GetCurrentContext(), 1, funcArgs).ToLocalChecked(); } -bool BufferObject::isBuffer(JSValueHandle value) +bool BufferObject::isBuffer(v8::Isolate* isolate, JSValueHandle value) { return !value.IsEmpty() && value->IsObject() && - value->ToObject()->Has(JSLiteral("ObjectType")) && - value->ToObject()->Get(JSLiteral("ObjectType"))->ToString()->Equals(JSLiteral("Buffer")); + value->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->Has(isolate->GetCurrentContext(),JSString(isolate,"ObjectType")).ToChecked() && + value->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->Get(isolate->GetCurrentContext(),JSString(isolate,"ObjectType")).ToLocalChecked()->Equals(isolate->GetCurrentContext(),JSString(isolate,"Buffer")).ToChecked(); } JS_CONSTRUCTOR_IMPL(BufferObject) { BufferObject* pBuffer = 0; - if (js_method_arg_length() == 1 && js_method_arg_is_number(0)) + if (js_method_args_length() == 1 && js_method_arg_is_number(0)) { pBuffer = new BufferObject(js_method_arg_as_integer(0)); } - else if (js_method_arg_length() == 1 && js_method_arg_is_string(0)) + else if (js_method_args_length() == 1 && js_method_arg_is_string(0)) { std::string str = js_method_arg_as_std_string(0); pBuffer = new BufferObject(); if (!js_string_to_byte_array(str, pBuffer->_buffer, true)) { delete pBuffer; - js_throw("Invalid String Elements"); + js_method_throw("Invalid String Elements"); } } - else if (js_method_arg_length() == 1 && js_method_arg_is_array(0)) + else if (js_method_args_length() == 1 && js_method_arg_is_array(0)) { JSArrayHandle array = js_method_arg_as_array(0); pBuffer = new BufferObject(); - if (!js_int_array_to_byte_array(array, pBuffer->_buffer, true)) + if (!js_int_array_to_byte_array(js_method_isolate(), array, pBuffer->_buffer, true)) { delete pBuffer; - js_throw("Invalid Array Elements"); + js_method_throw("Invalid Array Elements"); } } - else if (js_method_arg_length() == 1 && BufferObject::isBuffer(js_method_arg_as_object(0))) + else if (js_method_args_length() == 1 && BufferObject::isBuffer(js_method_isolate(), js_method_arg_as_object(0))) { - BufferObject* obj = js_method_arg_unwrap_object(BufferObject, 0); + BufferObject* obj = js_method_unwrap_object(BufferObject, 0); if (!obj) { - js_throw("Invalid Buffer Object"); + js_method_throw("Invalid Buffer Object"); } pBuffer = new BufferObject(*obj); } - else if(js_method_arg_length() != 0) + else if(js_method_args_length() != 0) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } else { pBuffer = new BufferObject(); } - pBuffer->Wrap(js_method_arg_self()); + pBuffer->Wrap(js_method_self()); - return js_method_arg_self(); + js_method_set_return_self(); } JS_METHOD_IMPL(BufferObject::size) { - return JSInteger(js_method_arg_unwrap_self(BufferObject)->_buffer.size()); + js_method_set_return_integer(js_method_unwrap_self(BufferObject)->_buffer.size()); } JS_METHOD_IMPL(BufferObject::fromArray) { - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_array(0); JSArrayHandle array = js_method_arg_as_array(0); bool resize = true; - if (js_method_arg_length() == 2) + if (js_method_args_length() == 2) { js_method_arg_assert_bool(1); resize = js_method_arg_as_bool(1); } - BufferObject* pBuffer = js_method_arg_unwrap_self(BufferObject); - if (!js_int_array_to_byte_array(array, pBuffer->_buffer, resize)) + BufferObject* pBuffer = js_method_unwrap_self(BufferObject); + if (!js_int_array_to_byte_array(js_method_isolate(), array, pBuffer->_buffer, resize)) { - js_throw("Invalid Array Elements"); + js_method_throw("Invalid Array Elements"); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(BufferObject::fromString) { - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_string(0); std::string str = js_method_arg_as_std_string(0); bool resize = true; - if (js_method_arg_length() == 2) + if (js_method_args_length() == 2) { js_method_arg_assert_bool(1); resize = js_method_arg_as_bool(1); } - BufferObject* pBuffer = js_method_arg_unwrap_self(BufferObject); + BufferObject* pBuffer = js_method_unwrap_self(BufferObject); if (!js_string_to_byte_array(str, pBuffer->_buffer, resize)) { - js_throw("Invalid Array Elements"); + js_method_throw("Invalid Array Elements"); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(BufferObject::fromBuffer) { - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_object(0); - if (!BufferObject::isBuffer(js_method_arg_as_object(0))) + if (!BufferObject::isBuffer(js_method_isolate(), js_method_arg_as_object(0))) { - js_throw("Invalid Argument"); + js_method_throw("Invalid Argument"); } bool resize = true; - if (js_method_arg_length() == 2) + if (js_method_args_length() == 2) { js_method_arg_assert_bool(1); resize = js_method_arg_as_bool(1); } - BufferObject* theirs = js_method_arg_unwrap_object(BufferObject, 0); - BufferObject* ours = js_method_arg_unwrap_self(BufferObject); + BufferObject* theirs = js_method_unwrap_object(BufferObject, 0); + BufferObject* ours = js_method_unwrap_self(BufferObject); if (resize) { ours->_buffer = theirs->_buffer; @@ -206,71 +207,72 @@ JS_METHOD_IMPL(BufferObject::fromBuffer) } } } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(BufferObject::toArray) { - BufferObject* pBuffer = js_method_arg_unwrap_self(BufferObject); + BufferObject* pBuffer = js_method_unwrap_self(BufferObject); uint32_t size = 0; - if (js_method_arg_length() == 1) + if (js_method_args_length() == 1) { size = js_method_arg_as_uint32(0); } - JSArrayHandle output = JSArray(size ? size : pBuffer->_buffer.size()); - js_byte_array_to_int_array(pBuffer->_buffer, output, size); - return output; + JSArrayHandle output = js_method_array(size ? size : pBuffer->_buffer.size()); + js_byte_array_to_int_array(js_method_isolate(), pBuffer->_buffer, output, size); + js_method_set_return_handle(output); } JS_METHOD_IMPL(BufferObject::toString) { - BufferObject* pBuffer = js_method_arg_unwrap_self(BufferObject); + BufferObject* pBuffer = js_method_unwrap_self(BufferObject); uint32_t size = pBuffer->_buffer.size(); - if (js_method_arg_length() == 1) + if (js_method_args_length() == 1) { size = js_method_arg_as_uint32(0); } std::string str((const char*)pBuffer->_buffer.data(), size); - return JSString(str.c_str(), strlen(str.c_str())); + js_method_set_return_string(str); } JS_METHOD_IMPL(BufferObject::equals) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_object(0); - if (!BufferObject::isBuffer(js_method_arg_as_object(0))) + if (!BufferObject::isBuffer(js_method_isolate(), js_method_arg_as_object(0))) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - BufferObject* theirs = js_method_arg_unwrap_object(BufferObject, 0); - BufferObject* ours = js_method_arg_unwrap_self(BufferObject); - return JSBoolean(ours->_buffer == theirs->_buffer); + BufferObject* theirs = js_method_unwrap_object(BufferObject, 0); + BufferObject* ours = js_method_unwrap_self(BufferObject); + js_method_set_return_boolean(ours->_buffer == theirs->_buffer); } JS_METHOD_IMPL(BufferObject::resize) { - BufferObject* buf = js_method_arg_unwrap_self(BufferObject); - js_method_arg_assert_size_eq(1); + BufferObject* buf = js_method_unwrap_self(BufferObject); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t size = js_method_arg_as_uint32(0); buf->buffer().resize(size); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(BufferObject::clear) { - BufferObject* buf = js_method_arg_unwrap_self(BufferObject); + BufferObject* buf = js_method_unwrap_self(BufferObject); buf->buffer().clear(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(BufferObject::isBufferObject) { - return JSBoolean(BufferObject::isBuffer(js_method_arg(0))); + js_method_set_return_boolean(BufferObject::isBuffer(js_method_isolate(), js_method_arg(0))); } // @@ -281,9 +283,9 @@ JS_INDEX_GETTER_IMPL(BufferObject::getAt) BufferObject* pBuffer = js_getter_info_unwrap_self(BufferObject); if (index >= pBuffer->_buffer.size()) { - js_throw("Index Out Of Range"); + js_method_throw("Index Out Of Range"); } - return JSUInt32(pBuffer->_buffer[js_getter_index()]); + js_method_set_return_handle(js_method_uint32(pBuffer->_buffer[js_getter_index()])); } JS_INDEX_SETTER_IMPL(BufferObject::setAt) @@ -292,15 +294,15 @@ JS_INDEX_SETTER_IMPL(BufferObject::setAt) if (js_setter_index() >= pBuffer->_buffer.size()) { - js_throw("Index Out Of Range"); + js_method_throw("Index Out Of Range"); } uint32_t val = js_setter_value_as_uint32(); if (val > 256) { - js_throw("Invalid Argument"); + js_method_throw("Invalid Argument"); } pBuffer->_buffer[js_setter_index()] = val; - return JSUndefined(); + js_method_set_return_undefined(); } @@ -308,7 +310,8 @@ JS_EXPORTS_INIT() { js_export_method("isBuffer", BufferObject::isBufferObject); js_export_class(BufferObject); - js_export_global_constructor("Buffer", BufferObject::_constructor); + JSFunctionHandle constructor = JSFunctionHandle::New( js_method_isolate(), BufferObject::_constructor ); + js_export_global_constructor("Buffer", constructor); // Must always be called last or code won't compile js_export_finalize(); diff --git a/src/js/modules/config/config.cpp b/src/js/modules/config/config.cpp index fbdf83230b..8b9c7b22a9 100644 --- a/src/js/modules/config/config.cpp +++ b/src/js/modules/config/config.cpp @@ -92,34 +92,34 @@ uint32_t ConfigObject::findSetting(config_setting_t* pSetting) JS_CONSTRUCTOR_IMPL(ConfigObject) { ConfigObject* pConfig = new ConfigObject(); - pConfig->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pConfig->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(ConfigObject::readFile) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); std::string path = js_method_arg_as_std_string(0); - return JSBoolean(!!config_read_file(&pConfig->getConfig(), path.c_str())); + js_method_set_return_boolean(!!config_read_file(&pConfig->getConfig(), path.c_str())); } JS_METHOD_IMPL(ConfigObject::writeFile) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); std::string path = js_method_arg_as_std_string(0); - return JSBoolean(!!config_write_file(&pConfig->getConfig(), path.c_str())); + js_method_set_return_boolean(!!config_write_file(&pConfig->getConfig(), path.c_str())); } JS_METHOD_IMPL(ConfigObject::toString) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t bufLen = js_method_arg_as_uint32(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); FILE* fp = ::fmemopen(0, bufLen, "w+"); config_write(&pConfig->getConfig(), fp); @@ -136,170 +136,180 @@ JS_METHOD_IMPL(ConfigObject::toString) } fclose(fp); - JSStringHandle result = JSString(chars, size); + JSStringHandle result = js_method_string(chars); delete[] chars; - return result; + js_method_set_return_handle(result); } JS_METHOD_IMPL(ConfigObject::lookupString) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string key = js_method_arg_as_std_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); const char* value; if (!config_lookup_string(&pConfig->getConfig(), key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(value); + js_method_set_return_string(value); } JS_METHOD_IMPL(ConfigObject::lookupFloat) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string key = js_method_arg_as_std_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); double value = 0; if (!config_lookup_float(&pConfig->getConfig(), key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSInteger(value); + js_method_set_return_integer(value); } JS_METHOD_IMPL(ConfigObject::lookupInteger) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string key = js_method_arg_as_std_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); int value = 0; if (!config_lookup_int(&pConfig->getConfig(), key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSInteger(value); + js_method_set_return_integer(value); } JS_METHOD_IMPL(ConfigObject::lookupBoolean) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string key = js_method_arg_as_std_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); int value = 0; if (!config_lookup_bool(&pConfig->getConfig(), key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSBoolean(!!value); + js_method_set_return_boolean(!!value); } JS_METHOD_IMPL(ConfigObject::lookupSetting) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string key = js_method_arg_as_std_string(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = config_lookup(&pConfig->getConfig(), key.c_str()); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - + uint32_t existingId = pConfig->findSetting(pSetting); if (existingId) { - return JSUInt32(existingId); + js_method_set_return_handle(js_method_uint32(existingId)); + return; } pConfig->_settings[++pConfig->_id] = pSetting; - return JSUInt32(pConfig->_id); + js_method_set_return_handle(js_method_uint32(pConfig->_id)); } JS_METHOD_IMPL(ConfigObject::rootSetting) { - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); if (pConfig->_rootSettingId) { - JSUInt32(pConfig->_rootSettingId); + js_method_set_return_handle(js_method_uint32(pConfig->_rootSettingId)); + return; } config_setting_t* pSetting = config_root_setting(&pConfig->getConfig()); if (!pSetting) { - return JSUndefined(); - } - + js_method_set_return_undefined(); + return; + } pConfig->_rootSettingId = ++pConfig->_id; pConfig->_settings[pConfig->_rootSettingId] = pSetting; - return JSUInt32(pConfig->_rootSettingId); + js_method_set_return_handle(js_method_uint32(pConfig->_rootSettingId)); } JS_METHOD_IMPL(ConfigObject::settingLength) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t settingId = js_method_arg_as_uint32(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSInt32(0); + js_method_set_return_handle(js_method_int32(0)); } uint32_t count = config_setting_length(pSetting); - return JSInt32(count); + js_method_set_return_handle(js_method_int32(count)); } JS_METHOD_IMPL(ConfigObject::settingType) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t settingId = js_method_arg_as_uint32(0); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } int type = config_setting_type(pSetting); - return JSInt32(type); + js_method_set_return_handle(js_method_int32(type)); } JS_METHOD_IMPL(ConfigObject::settingLookupString) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); uint32_t settingId = js_method_arg_as_uint32(0); std::string key = js_method_arg_as_std_string(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } const char* value; if (!key.empty()) { if (!config_setting_lookup_string(pSetting, key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } } else if (config_setting_type(pSetting) == CONFIG_TYPE_STRING) @@ -307,136 +317,145 @@ JS_METHOD_IMPL(ConfigObject::settingLookupString) value = config_setting_get_string(pSetting); } - return JSString(value); + js_method_set_return_string(value); } JS_METHOD_IMPL(ConfigObject::settingLookupInteger) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); uint32_t settingId = js_method_arg_as_uint32(0); std::string key = js_method_arg_as_std_string(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } int value = 0; if (!key.empty()) { if (!config_setting_lookup_int(pSetting, key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } } else if (config_setting_type(pSetting) == CONFIG_TYPE_INT) { value = config_setting_get_int(pSetting); } - return JSInt32(value); + js_method_set_return_handle(js_method_int32(value)); } JS_METHOD_IMPL(ConfigObject::settingLookupFloat) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); uint32_t settingId = js_method_arg_as_uint32(0); std::string key = js_method_arg_as_std_string(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } double value = 0; if (!key.empty()) { if (!config_setting_lookup_float(pSetting, key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } } else if (config_setting_type(pSetting) == CONFIG_TYPE_FLOAT) { value = config_setting_get_float(pSetting); } - return JSInteger(value); + js_method_set_return_integer(value); } JS_METHOD_IMPL(ConfigObject::settingLookupBoolean) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); uint32_t settingId = js_method_arg_as_uint32(0); std::string key = js_method_arg_as_std_string(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } int value = 0; if (!key.empty()) { if (!config_setting_lookup_bool(pSetting, key.c_str(), &value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } } else if (config_setting_type(pSetting) == CONFIG_TYPE_BOOL) { value = config_setting_get_bool(pSetting); } - return JSBoolean(!!value); + js_method_set_return_boolean(!!value); } JS_METHOD_IMPL(ConfigObject::settingLookupSetting) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); uint32_t settingId = js_method_arg_as_uint32(0); std::string key = js_method_arg_as_std_string(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); config_setting_t* pChildSetting = config_setting_get_member(pSetting, key.c_str()); if (!pSetting || !pChildSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } uint32_t existingId = pConfig->findSetting(pChildSetting); if (existingId) { - return JSUInt32(existingId); + js_method_set_return_handle(js_method_uint32(existingId)); + return; } pConfig->_settings[++pConfig->_id] = pChildSetting; - return JSUInt32(pConfig->_id); + js_method_set_return_handle(js_method_uint32(pConfig->_id)); } JS_METHOD_IMPL(ConfigObject::settingLookupElement) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_uint32(1); uint32_t settingId = js_method_arg_as_uint32(0); uint32_t index = js_method_arg_as_uint32(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } config_setting_t* pElement = config_setting_get_elem(pSetting, index); @@ -444,17 +463,18 @@ JS_METHOD_IMPL(ConfigObject::settingLookupElement) uint32_t existingId = pConfig->findSetting(pElement); if (existingId) { - return JSUInt32(existingId); + js_method_set_return_handle(js_method_uint32(existingId)); + return; } pConfig->_settings[++pConfig->_id] = pElement; - return JSUInt32(pConfig->_id); + js_method_set_return_handle(js_method_uint32(pConfig->_id)); } JS_METHOD_IMPL(ConfigObject::settingAddSetting) { - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); js_method_arg_assert_int32(2); @@ -463,88 +483,88 @@ JS_METHOD_IMPL(ConfigObject::settingAddSetting) std::string key = js_method_arg_as_std_string(1); int type = js_method_arg_as_int32(2); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); config_setting_t* pChildSetting = config_setting_add(pSetting, key.empty() ? 0 : key.c_str(), type); pConfig->_settings[++pConfig->_id] = pChildSetting; - return JSUInt32(pConfig->_id); + js_method_set_return_handle(js_method_uint32(pConfig->_id)); } JS_METHOD_IMPL(ConfigObject::settingSetAsString) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); uint32_t settingId = js_method_arg_as_uint32(0); std::string value = js_method_arg_as_std_string(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - js_throw("Config Setting Not Found"); + js_method_throw("Config Setting Not Found"); } - return JSBoolean(!!config_setting_set_string(pSetting, value.c_str())); + js_method_set_return_boolean(!!config_setting_set_string(pSetting, value.c_str())); } JS_METHOD_IMPL(ConfigObject::settingSetAsInteger) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_int32(1); uint32_t settingId = js_method_arg_as_uint32(0); int value = js_method_arg_as_int32(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - js_throw("Config Setting Not Found"); + js_method_throw("Config Setting Not Found"); } - return JSBoolean(!!config_setting_set_int(pSetting, value)); + js_method_set_return_boolean(!!config_setting_set_int(pSetting, value)); } JS_METHOD_IMPL(ConfigObject::settingSetAsBoolean) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_bool(1); uint32_t settingId = js_method_arg_as_uint32(0); bool value = js_method_arg_as_bool(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - js_throw("Config Setting Not Found"); + js_method_throw("Config Setting Not Found"); } - return JSBoolean(!!config_setting_set_bool(pSetting, value)); + js_method_set_return_boolean(!!config_setting_set_bool(pSetting, value)); } JS_METHOD_IMPL(ConfigObject::settingSetAsFloat) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_number(1); uint32_t settingId = js_method_arg_as_uint32(0); double value = js_method_arg_as_number(1); - ConfigObject* pConfig = js_method_arg_unwrap_self(ConfigObject); + ConfigObject* pConfig = js_method_unwrap_self(ConfigObject); config_setting_t* pSetting = pConfig->findSetting(settingId); if (!pSetting) { - js_throw("Config Setting Not Found"); + js_method_throw("Config Setting Not Found"); } - return JSBoolean(!!config_setting_set_float(pSetting, value)); + js_method_set_return_boolean(!!config_setting_set_float(pSetting, value)); } JS_EXPORTS_INIT() diff --git a/src/js/modules/constants/constants.cpp b/src/js/modules/constants/constants.cpp index d1b5f32fa5..3d5903f346 100644 --- a/src/js/modules/constants/constants.cpp +++ b/src/js/modules/constants/constants.cpp @@ -24,11 +24,8 @@ #include #include -static v8::Handle init_exports(const v8::Arguments& args) -{ - v8::HandleScope scope; - v8::Persistent exports = v8::Persistent::New(v8::Object::New()); - +JS_EXPORTS_INIT() +{ // // Mutable Properties // @@ -37,64 +34,64 @@ static v8::Handle init_exports(const v8::Arguments& args) // Standard fcntl system constants // #ifdef __USE_XOPEN2K8 - CONST_EXPORT(O_DIRECTORY); /* Must be a directory. */ - CONST_EXPORT(O_NOFOLLOW); /* Do not follow links. */ - CONST_EXPORT(O_CLOEXEC); /* Set close_on_exec. */ + js_export_const(O_DIRECTORY); /* Must be a directory. */ + js_export_const(O_NOFOLLOW); /* Do not follow links. */ + js_export_const(O_CLOEXEC); /* Set close_on_exec. */ #endif #ifdef __USE_GNU - CONST_EXPORT(O_DIRECT); /* Direct disk access. */ - CONST_EXPORT(O_NOATIME); /* Do not set atime. */ - CONST_EXPORT(O_PATH); /* Resolve pathname but do not open file. */ + js_export_const(O_DIRECT); /* Direct disk access. */ + js_export_const(O_NOATIME); /* Do not set atime. */ + js_export_const(O_PATH); /* Resolve pathname but do not open file. */ #ifdef O_TMPFILE - CONST_EXPORT(O_TMPFILE); /* Atomically create nameless file. */ + js_export_const(O_TMPFILE); /* Atomically create nameless file. */ #endif #endif - CONST_EXPORT(STDOUT_FILENO); - CONST_EXPORT(STDIN_FILENO); - CONST_EXPORT(STDERR_FILENO); + js_export_const(STDOUT_FILENO); + js_export_const(STDIN_FILENO); + js_export_const(STDERR_FILENO); // // Signals // - CONST_EXPORT(SIGHUP); /* Hangup (POSIX). */ - CONST_EXPORT(SIGINT); /* Interrupt (ANSI). */ - CONST_EXPORT(SIGQUIT); /* Quit (POSIX). */ - CONST_EXPORT(SIGILL); /* Illegal instruction (ANSI). */ - CONST_EXPORT(SIGTRAP); /* Trace trap (POSIX). */ - CONST_EXPORT(SIGABRT); /* Abort (ANSI). */ - CONST_EXPORT(SIGIOT); /* IOT trap (4.2 BSD). */ - CONST_EXPORT(SIGBUS); /* BUS error (4.2 BSD). */ - CONST_EXPORT(SIGFPE); /* Floating-point exception (ANSI). */ - CONST_EXPORT(SIGKILL); /* Kill, unblockable (POSIX). */ - CONST_EXPORT(SIGUSR1); /* User-defined signal 1 (POSIX). */ - CONST_EXPORT(SIGSEGV); /* Segmentation violation (ANSI). */ - CONST_EXPORT(SIGUSR2); /* User-defined signal 2 (POSIX). */ - CONST_EXPORT(SIGPIPE); /* Broken pipe (POSIX). */ - CONST_EXPORT(SIGALRM); /* Alarm clock (POSIX). */ - CONST_EXPORT(SIGCHLD); /* Child status has changed (POSIX). */ - CONST_EXPORT(SIGCONT); /* Continue (POSIX). */ - CONST_EXPORT(SIGSTOP); /* Stop, unblockable (POSIX). */ - CONST_EXPORT(SIGTSTP); /* Keyboard stop (POSIX). */ - CONST_EXPORT(SIGTTIN); /* Background read from tty (POSIX). */ - CONST_EXPORT(SIGTTOU); /* Background write to tty (POSIX). */ - CONST_EXPORT(SIGURG); /* Urgent condition on socket (4.2 BSD). */ - CONST_EXPORT(SIGXCPU); /* CPU limit exceeded (4.2 BSD). */ - CONST_EXPORT(SIGXFSZ); /* File size limit exceeded (4.2 BSD). */ - CONST_EXPORT(SIGVTALRM);/* Virtual alarm clock (4.2 BSD). */ - CONST_EXPORT(SIGPROF); /* Profiling alarm clock (4.2 BSD). */ - CONST_EXPORT(SIGSYS); /* Bad system call. */ - CONST_EXPORT(SIGTERM); /* Termination (ANSI). */ - CONST_EXPORT(SIGWINCH); /* Window size change (4.3 BSD, Sun). */ - CONST_EXPORT(SIGIO); /* I/O now possible (4.2 BSD). */ + js_export_const(SIGHUP); /* Hangup (POSIX). */ + js_export_const(SIGINT); /* Interrupt (ANSI). */ + js_export_const(SIGQUIT); /* Quit (POSIX). */ + js_export_const(SIGILL); /* Illegal instruction (ANSI). */ + js_export_const(SIGTRAP); /* Trace trap (POSIX). */ + js_export_const(SIGABRT); /* Abort (ANSI). */ + js_export_const(SIGIOT); /* IOT trap (4.2 BSD). */ + js_export_const(SIGBUS); /* BUS error (4.2 BSD). */ + js_export_const(SIGFPE); /* Floating-point exception (ANSI). */ + js_export_const(SIGKILL); /* Kill, unblockable (POSIX). */ + js_export_const(SIGUSR1); /* User-defined signal 1 (POSIX). */ + js_export_const(SIGSEGV); /* Segmentation violation (ANSI). */ + js_export_const(SIGUSR2); /* User-defined signal 2 (POSIX). */ + js_export_const(SIGPIPE); /* Broken pipe (POSIX). */ + js_export_const(SIGALRM); /* Alarm clock (POSIX). */ + js_export_const(SIGCHLD); /* Child status has changed (POSIX). */ + js_export_const(SIGCONT); /* Continue (POSIX). */ + js_export_const(SIGSTOP); /* Stop, unblockable (POSIX). */ + js_export_const(SIGTSTP); /* Keyboard stop (POSIX). */ + js_export_const(SIGTTIN); /* Background read from tty (POSIX). */ + js_export_const(SIGTTOU); /* Background write to tty (POSIX). */ + js_export_const(SIGURG); /* Urgent condition on socket (4.2 BSD). */ + js_export_const(SIGXCPU); /* CPU limit exceeded (4.2 BSD). */ + js_export_const(SIGXFSZ); /* File size limit exceeded (4.2 BSD). */ + js_export_const(SIGVTALRM);/* Virtual alarm clock (4.2 BSD). */ + js_export_const(SIGPROF); /* Profiling alarm clock (4.2 BSD). */ + js_export_const(SIGSYS); /* Bad system call. */ + js_export_const(SIGTERM); /* Termination (ANSI). */ + js_export_const(SIGWINCH); /* Window size change (4.3 BSD, Sun). */ + js_export_const(SIGIO); /* I/O now possible (4.2 BSD). */ #if !OSS_PLATFORM_MAC_OS_X - CONST_EXPORT(SIGSTKFLT);/* Stack fault. */ - CONST_EXPORT(SIGPWR); /* Power failure restart (System V). */ - CONST_EXPORT(SIGPOLL); /* Pollable event occurred (System V). */ - CONST_EXPORT(SIGCLD); /* Same as SIGCHLD (System V). */ + js_export_const(SIGSTKFLT);/* Stack fault. */ + js_export_const(SIGPWR); /* Power failure restart (System V). */ + js_export_const(SIGPOLL); /* Pollable event occurred (System V). */ + js_export_const(SIGCLD); /* Same as SIGCHLD (System V). */ #endif - return exports; + js_export_finalize(); } JS_REGISTER_MODULE(Const); diff --git a/src/js/modules/dns/dns.cpp b/src/js/modules/dns/dns.cpp index e8871a1513..ad3ac64d23 100644 --- a/src/js/modules/dns/dns.cpp +++ b/src/js/modules/dns/dns.cpp @@ -38,7 +38,7 @@ typedef OSS::BlockingQueue ContextPool; typedef std::map ContextMap; static ContextPool _pool; static ContextMap _map; -JSPersistentFunctionHandle* _work_cb = 0; +JSCopyablePersistentFunctionHandle* _work_cb = 0; pollfd pfds[POOL_SIZE]; static void initialize_pool(uint32_t size) @@ -69,303 +69,340 @@ static void relinquish_context(DNSResolver* resolver) } template -void call_result_callback(const T& record, const JSLocalValueHandle& result, void* userData) +void call_result_callback( v8::Isolate* isolate, const T& record, const JSLocalValueHandle& result, void* userData) { - JSPersistentFunctionHandle* cb = (JSPersistentFunctionHandle*)userData; + v8::Local context = isolate->GetCurrentContext(); + v8::Local global = context->Global(); + + JSCopyablePersistentFunctionHandle* persistentCallback = (JSCopyablePersistentFunctionHandle*)userData; - JSLocalValueHandle common = JSObject(); - common->ToObject()->Set(JSLiteral("cname"), JSString(record.getCName().c_str())); - common->ToObject()->Set(JSLiteral("qname"), JSString(record.getQName().c_str())); - common->ToObject()->Set(JSLiteral("ttl"), JSUInt32(record.getTTL())); + JSLocalValueHandle common = JSObject(isolate); + common->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"cname"), JSString(isolate,record.getCName().c_str())); + common->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"qname"), JSString(isolate,record.getQName().c_str())); + common->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"ttl"), JSUint32(isolate,record.getTTL())); JSLocalArgumentVector args; args.push_back(result); args.push_back(common); + + JSFunctionHandle callback = persistentCallback->Get(isolate); - JSValueHandle obj = (*cb)->Get(JSLiteral("resolver")); - DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj->ToObject()); + JSValueHandle obj = callback->Get(context, JSString(isolate, "resolver")).ToLocalChecked(); + + DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj->ToObject(context).ToLocalChecked()); relinquish_context(resolver); - if (obj->ToObject()->HasOwnProperty(JSLiteral("timerId"))) + if (obj->ToObject(context).ToLocalChecked()->HasOwnProperty(context,JSString(isolate,"timerId")).ToChecked()) { - JSValueHandle timerId = obj->ToObject()->Get(JSLiteral("timerId")); - Async::clear_timer(timerId->ToInt32()->Value()); + JSValueHandle timerId = obj->ToObject(context).ToLocalChecked()->Get(context,JSString(isolate,"timerId")).ToLocalChecked(); + Async::clear_timer(timerId->Int32Value(context).ToChecked()); } - (*cb)->Call(js_get_global(), args.size(), args.data()); - cb->Dispose(); - delete cb; + callback->Call(context, global, args.size(), args.data()); + persistentCallback->Reset(); + delete persistentCallback; - (*_work_cb)->Call(js_get_global(), 0, 0); + JSFunctionHandle workCallback = _work_cb->Get(isolate); + + workCallback->Call(context, global, 0, 0); } static void on_a_lookup(const DNSARecordV4& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSAddressList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate, records.size()); std::size_t index = 0; for (DNSAddressList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - result->ToObject()->Set(index++, JSString(*iter)); + result->ToObject(context).ToLocalChecked()->Set(context, index++, JSString(isolate, *iter)); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } static void on_aaaa_lookup(const DNSARecordV6& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSAddressList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate, records.size()); std::size_t index = 0; for (DNSAddressList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - result->ToObject()->Set(index++, JSString(*iter)); + result->ToObject(context).ToLocalChecked()->Set(context, index++, JSString(isolate, *iter)); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } static void on_srv_lookup(const DNSSRVRecord& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSSRVRecordList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate,records.size()); std::size_t index = 0; for (DNSSRVRecordList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - JSObjectHandle srv = JSObject(); - srv->Set(JSLiteral("priority"), JSInt32(iter->priority)); - srv->Set(JSLiteral("weight"), JSInt32(iter->weight)); - srv->Set(JSLiteral("port"), JSInt32(iter->port)); - srv->Set(JSLiteral("name"), JSString(iter->name)); - result->ToObject()->Set(index++, srv); + JSObjectHandle srv = JSObject(isolate); + srv->Set(context,JSString(isolate,"priority"), JSInt32(isolate,iter->priority)); + srv->Set(context,JSString(isolate,"weight"), JSInt32(isolate,iter->weight)); + srv->Set(context,JSString(isolate,"port"), JSInt32(isolate,iter->port)); + srv->Set(context,JSString(isolate,"name"), JSString(isolate,iter->name)); + result->ToObject(context).ToLocalChecked()->Set(context, index++, srv); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } static void on_ptr_lookup(const DNSPTRRecord& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSPTRRecordList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate,records.size()); std::size_t index = 0; for (DNSPTRRecordList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - result->ToObject()->Set(index++, JSString(*iter)); + result->ToObject(context).ToLocalChecked()->Set(context, index++, JSString(isolate,*iter)); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } static void on_txt_lookup(const DNSTXTRecord& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSTXTRecordList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate,records.size()); std::size_t index = 0; for (DNSTXTRecordList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - result->ToObject()->Set(index++, JSString(*iter)); + result->ToObject(context).ToLocalChecked()->Set(context, index++, JSString(isolate,*iter)); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } static void on_naptr_lookup(const DNSNAPTRRecord& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSNAPTRRecordList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate,records.size()); std::size_t index = 0; for (DNSNAPTRRecordList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - JSObjectHandle srv = JSObject(); - srv->Set(JSLiteral("order"), JSInt32(iter->order)); - srv->Set(JSLiteral("preference"), JSInt32(iter->preference)); - srv->Set(JSLiteral("flags"), JSString(iter->flags)); - srv->Set(JSLiteral("service"), JSString(iter->service)); - srv->Set(JSLiteral("regexp"), JSString(iter->regexp)); - srv->Set(JSLiteral("replacement"), JSString(iter->flags)); - result->ToObject()->Set(index++, srv); + JSObjectHandle srv = JSObject(isolate); + srv->Set(context, JSString(isolate,"order"), JSInt32(isolate,iter->order)); + srv->Set(context, JSString(isolate,"preference"), JSInt32(isolate,iter->preference)); + srv->Set(context, JSString(isolate,"flags"), JSString(isolate,iter->flags)); + srv->Set(context, JSString(isolate,"service"), JSString(isolate,iter->service)); + srv->Set(context, JSString(isolate,"regexp"), JSString(isolate,iter->regexp)); + srv->Set(context, JSString(isolate,"replacement"), JSString(isolate,iter->flags)); + result->ToObject(context).ToLocalChecked()->Set(context, index++, srv); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } static void on_mx_lookup(const DNSMXRecord& record, void* userData) { + v8::Isolate* isolate = js_get_v8_isolate(); + v8::Local context = isolate->GetCurrentContext(); + const DNSMXRecordList& records = record.getRecords(); - JSLocalValueHandle result = JSArray(records.size()); + JSLocalValueHandle result = JSArray(isolate,records.size()); std::size_t index = 0; for (DNSMXRecordList::const_iterator iter = records.begin(); iter != records.end(); iter++) { - JSObjectHandle srv = JSObject(); - srv->Set(JSLiteral("priority"), JSInt32(iter->priority)); - srv->Set(JSLiteral("name"), JSString(iter->name)); - result->ToObject()->Set(index++, srv); + JSObjectHandle srv = JSObject(isolate); + srv->Set(context,JSString(isolate,"priority"), JSInt32(isolate,iter->priority)); + srv->Set(context,JSString(isolate,"name"), JSString(isolate,iter->name)); + result->ToObject(context).ToLocalChecked()->Set(context,index++, srv); } - call_result_callback(record, result, userData); + call_result_callback(isolate, record, result, userData); } JS_METHOD_IMPL(__lookup_a) { static DNSARecordV4CB resolver_cb = boost::bind(on_a_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(),js_method_string("resolver"), obj); - resolver->resolveA4(query, 0, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolveA4(query, 0, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_aaaa) { static DNSARecordV6CB resolver_cb = boost::bind(on_aaaa_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolveA6(query, 0, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolveA6(query, 0, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_srv) { static DNSSRVRecordCB resolver_cb = boost::bind(on_srv_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolveSRV(query, 0, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolveSRV(query, 0, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_ptr4) { static DNSPTRRecordCB resolver_cb = boost::bind(on_ptr_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolvePTR4(query, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolvePTR4(query, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_ptr6) { static DNSPTRRecordCB resolver_cb = boost::bind(on_ptr_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolvePTR6(query, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolvePTR6(query, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_naptr) { static DNSNAPTRRecordCB resolver_cb = boost::bind(on_naptr_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolveNAPTR(query, 0, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolveNAPTR(query, 0, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_txt) { static DNSTXTRecordCB resolver_cb = boost::bind(on_txt_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolveTXT(query, 0, DNS_C_ANY, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolveTXT(query, 0, DNS_C_ANY, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__lookup_mx) { static DNSMXRecordCB resolver_cb = boost::bind(on_mx_lookup, _1, _2); - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_function(1); js_method_arg_assert_object(2); std::string query = js_method_arg_as_std_string(0); - JSPersistentFunctionHandle* cb = new JSPersistentFunctionHandle; - *cb = js_method_arg_as_persistent_function(1); + JSCopyablePersistentFunctionHandle* persistentCallback = new JSCopyablePersistentFunctionHandle; + *persistentCallback = js_method_arg_as_persistent_function(1); + JSFunctionHandle callback = persistentCallback->Get(js_method_isolate()); JSLocalObjectHandle obj = js_method_arg_as_object(2); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); - (*cb)->Set(JSLiteral("resolver"), obj); + callback->Set(js_method_context(), js_method_string("resolver"), obj); - resolver->resolveMX(query, 0, resolver_cb, cb); - return JSInt32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0)); + resolver->resolveMX(query, 0, resolver_cb, persistentCallback); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(),MAX_TIMEOUT_SEC, 0))); } JS_METHOD_IMPL(__relinquish_context) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_object(0); JSLocalObjectHandle obj = js_method_arg_as_object(0); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); relinquish_context(resolver); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__acquire_context) @@ -375,23 +412,23 @@ JS_METHOD_IMPL(__acquire_context) _pool.dequeue(resolver); if (!resolver) { - js_throw("Unable to acquire context"); + js_method_throw("Unable to acquire context"); } - JSObjectHandle obj = js_wrap_pointer_to_local_object(resolver); - obj->Set(JSLiteral("fd"), JSUInt32(resolver->context()->getSocketFd())); + JSObjectHandle obj = js_method_wrap_pointer_to_local_object(resolver); + obj->Set(js_method_context(), js_method_string("fd"), js_method_uint32(resolver->context()->getSocketFd())); - return obj; + js_method_set_return_handle(obj); } JS_METHOD_IMPL(__get_context_count) { - return JSUInt32(_pool.size()); + js_method_set_return_handle(js_method_uint32(_pool.size())); } JS_METHOD_IMPL(__process_io_events) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t fd = js_method_arg_as_uint32(0); @@ -400,29 +437,30 @@ JS_METHOD_IMPL(__process_io_events) { dns_ioevent(iter->second->context(), 0); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__set_work_callback) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_function(0); - _work_cb = new JSPersistentFunctionHandle; + _work_cb = new JSCopyablePersistentFunctionHandle; *_work_cb = js_method_arg_as_persistent_function(0); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__get_next_context_timeout) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_object(0); JSLocalObjectHandle obj = js_method_arg_as_object(0); DNSResolver* resolver = js_unwrap_pointer_from_local_object(obj); if (!resolver) { - return JSInt32(-1); + js_method_set_return_handle(js_method_int32(-1)); + return; } - return JSInt32(dns_timeouts(resolver->context()->context(), MAX_TIMEOUT_SEC, 0)); + js_method_set_return_handle(js_method_int32(dns_timeouts(resolver->context()->context(), MAX_TIMEOUT_SEC, 0))); } diff --git a/src/js/modules/error/error.cpp b/src/js/modules/error/error.cpp index 6c8e8b72fd..be63b3a1a2 100644 --- a/src/js/modules/error/error.cpp +++ b/src/js/modules/error/error.cpp @@ -23,162 +23,159 @@ #include #include -static v8::Handle __errno_get(v8::Local property, const v8::AccessorInfo& info) +JS_ACCESSOR_GETTER_IMPL(__errno_get) { - return v8::Integer::New(errno); + js_method_set_return_integer(errno); } -static v8::Handle init_exports(const v8::Arguments& args) +JS_EXPORTS_INIT() { - v8::HandleScope scope; - v8::Persistent exports = v8::Persistent::New(v8::Object::New()); - // // Mutable Properties // - exports->SetAccessor(v8::String::New("errno"), __errno_get, 0); + js_export_accessor(("errno"),__errno_get, NULL); // // Standard system errors // - CONST_EXPORT(EPERM); /* Operation not permitted */ - CONST_EXPORT(ENOENT); /* No such file or directory */ - CONST_EXPORT(ESRCH); /* No such process */ - CONST_EXPORT(EINTR); /* Interrupted system call */ - CONST_EXPORT(EIO); /* I/O error */ - CONST_EXPORT(ENXIO); /* No such device or address */ - CONST_EXPORT(E2BIG); /* Argument list too long */ - CONST_EXPORT(ENOEXEC); /* Exec format error */ - CONST_EXPORT(EBADF); /* Bad file number */ - CONST_EXPORT(ECHILD); /* No child processes */ - CONST_EXPORT(EAGAIN); /* Try again */ - CONST_EXPORT(ENOMEM); /* Out of memory */ - CONST_EXPORT(EACCES); /* Permission denied */ - CONST_EXPORT(EFAULT); /* Bad address */ - CONST_EXPORT(ENOTBLK); /* Block device required */ - CONST_EXPORT(EBUSY); /* Device or resource busy */ - CONST_EXPORT(EEXIST); /* File exists */ - CONST_EXPORT(EXDEV); /* Cross-device link */ - CONST_EXPORT(ENODEV); /* No such device */ - CONST_EXPORT(ENOTDIR); /* Not a directory */ - CONST_EXPORT(EISDIR); /* Is a directory */ - CONST_EXPORT(EINVAL); /* Invalid argument */ - CONST_EXPORT(ENFILE); /* File table overflow */ - CONST_EXPORT(EMFILE); /* Too many open files */ - CONST_EXPORT(ENOTTY); /* Not a typewriter */ - CONST_EXPORT(ETXTBSY); /* Text file busy */ - CONST_EXPORT(EFBIG); /* File too large */ - CONST_EXPORT(ENOSPC); /* No space left on device */ - CONST_EXPORT(ESPIPE); /* Illegal seek */ - CONST_EXPORT(EROFS); /* Read-only file system */ - CONST_EXPORT(EMLINK); /* Too many links */ - CONST_EXPORT(EPIPE); /* Broken pipe */ - CONST_EXPORT(EDOM); /* Math argument out of domain of func */ - CONST_EXPORT(ERANGE); /* Math result not representable */ - CONST_EXPORT(EDEADLK); /* Resource deadlock would occur */ - CONST_EXPORT(ENAMETOOLONG); /* File name too long */ - CONST_EXPORT(ENOLCK); /* No record locks available */ - CONST_EXPORT(ENOSYS); /* Invalid system call number */ - CONST_EXPORT(ENOTEMPTY); /* Directory not empty */ - CONST_EXPORT(ELOOP); /* Too many symbolic links encountered */ - CONST_EXPORT(EWOULDBLOCK); /* Operation would block */ - CONST_EXPORT(ENOMSG); /* No message of desired type */ - CONST_EXPORT(EIDRM); /* Identifier removed */ - CONST_EXPORT(ENOSTR); /* Device not a stream */ - CONST_EXPORT(ENODATA); /* No data available */ - CONST_EXPORT(ETIME); /* Timer expired */ - CONST_EXPORT(ENOSR); /* Out of streams resources */ - CONST_EXPORT(EREMOTE); /* Object is remote */ - CONST_EXPORT(ENOLINK); /* Link has been severed */ - CONST_EXPORT(EPROTO); /* Protocol error */ - CONST_EXPORT(EMULTIHOP); /* Multihop attempted */ - CONST_EXPORT(EBADMSG); /* Not a data message */ - CONST_EXPORT(EOVERFLOW); /* Value too large for defined data type */ - CONST_EXPORT(EILSEQ); /* Illegal byte sequence */ - CONST_EXPORT(EUSERS); /* Too many users */ - CONST_EXPORT(ENOTSOCK); /* Socket operation on non-socket */ - CONST_EXPORT(EDESTADDRREQ); /* Destination address required */ - CONST_EXPORT(EMSGSIZE); /* Message too long */ - CONST_EXPORT(EPROTOTYPE); /* Protocol wrong type for socket */ - CONST_EXPORT(ENOPROTOOPT); /* Protocol not available */ - CONST_EXPORT(EPROTONOSUPPORT);/* Protocol not supported */ - CONST_EXPORT(ESOCKTNOSUPPORT);/* Socket type not supported */ - CONST_EXPORT(EOPNOTSUPP); /* Operation not supported on transport endpoint */ - CONST_EXPORT(EPFNOSUPPORT); /* Protocol family not supported */ - CONST_EXPORT(EAFNOSUPPORT); /* Address family not supported by protocol */ - CONST_EXPORT(EADDRINUSE); /* Address already in use */ - CONST_EXPORT(EADDRNOTAVAIL); /* Cannot assign requested address */ - CONST_EXPORT(ENETDOWN); /* Network is down */ - CONST_EXPORT(ENETUNREACH); /* Network is unreachable */ - CONST_EXPORT(ENETRESET); /* Network dropped connection because of reset */ - CONST_EXPORT(ECONNABORTED); /* Software caused connection abort */ - CONST_EXPORT(ECONNRESET); /* Connection reset by peer */ - CONST_EXPORT(ENOBUFS); /* No buffer space available */ - CONST_EXPORT(EISCONN); /* Transport endpoint is already connected */ - CONST_EXPORT(ENOTCONN); /* Transport endpoint is not connected */ - CONST_EXPORT(ESHUTDOWN); /* Cannot send after transport endpoint shutdown */ - CONST_EXPORT(ETOOMANYREFS); /* Too many references: cannot splice */ - CONST_EXPORT(ETIMEDOUT); /* Connection timed out */ - CONST_EXPORT(ECONNREFUSED); /* Connection refused */ - CONST_EXPORT(EHOSTDOWN); /* Host is down */ - CONST_EXPORT(EHOSTUNREACH); /* No route to host */ - CONST_EXPORT(EALREADY); /* Operation already in progress */ - CONST_EXPORT(EINPROGRESS); /* Operation now in progress */ - CONST_EXPORT(ESTALE); /* Stale file handle */ - CONST_EXPORT(EDQUOT); /* Quota exceeded */ - CONST_EXPORT(ECANCELED); /* Operation Canceled */ - CONST_EXPORT(EOWNERDEAD); /* Owner died */ - CONST_EXPORT(ENOTRECOVERABLE);/* State not recoverable */ + js_export_const(EPERM); /* Operation not permitted */ + js_export_const(ENOENT); /* No such file or directory */ + js_export_const(ESRCH); /* No such process */ + js_export_const(EINTR); /* Interrupted system call */ + js_export_const(EIO); /* I/O error */ + js_export_const(ENXIO); /* No such device or address */ + js_export_const(E2BIG); /* Argument list too long */ + js_export_const(ENOEXEC); /* Exec format error */ + js_export_const(EBADF); /* Bad file number */ + js_export_const(ECHILD); /* No child processes */ + js_export_const(EAGAIN); /* Try again */ + js_export_const(ENOMEM); /* Out of memory */ + js_export_const(EACCES); /* Permission denied */ + js_export_const(EFAULT); /* Bad address */ + js_export_const(ENOTBLK); /* Block device required */ + js_export_const(EBUSY); /* Device or resource busy */ + js_export_const(EEXIST); /* File exists */ + js_export_const(EXDEV); /* Cross-device link */ + js_export_const(ENODEV); /* No such device */ + js_export_const(ENOTDIR); /* Not a directory */ + js_export_const(EISDIR); /* Is a directory */ + js_export_const(EINVAL); /* Invalid argument */ + js_export_const(ENFILE); /* File table overflow */ + js_export_const(EMFILE); /* Too many open files */ + js_export_const(ENOTTY); /* Not a typewriter */ + js_export_const(ETXTBSY); /* Text file busy */ + js_export_const(EFBIG); /* File too large */ + js_export_const(ENOSPC); /* No space left on device */ + js_export_const(ESPIPE); /* Illegal seek */ + js_export_const(EROFS); /* Read-only file system */ + js_export_const(EMLINK); /* Too many links */ + js_export_const(EPIPE); /* Broken pipe */ + js_export_const(EDOM); /* Math argument out of domain of func */ + js_export_const(ERANGE); /* Math result not representable */ + js_export_const(EDEADLK); /* Resource deadlock would occur */ + js_export_const(ENAMETOOLONG); /* File name too long */ + js_export_const(ENOLCK); /* No record locks available */ + js_export_const(ENOSYS); /* Invalid system call number */ + js_export_const(ENOTEMPTY); /* Directory not empty */ + js_export_const(ELOOP); /* Too many symbolic links encountered */ + js_export_const(EWOULDBLOCK); /* Operation would block */ + js_export_const(ENOMSG); /* No message of desired type */ + js_export_const(EIDRM); /* Identifier removed */ + js_export_const(ENOSTR); /* Device not a stream */ + js_export_const(ENODATA); /* No data available */ + js_export_const(ETIME); /* Timer expired */ + js_export_const(ENOSR); /* Out of streams resources */ + js_export_const(EREMOTE); /* Object is remote */ + js_export_const(ENOLINK); /* Link has been severed */ + js_export_const(EPROTO); /* Protocol error */ + js_export_const(EMULTIHOP); /* Multihop attempted */ + js_export_const(EBADMSG); /* Not a data message */ + js_export_const(EOVERFLOW); /* Value too large for defined data type */ + js_export_const(EILSEQ); /* Illegal byte sequence */ + js_export_const(EUSERS); /* Too many users */ + js_export_const(ENOTSOCK); /* Socket operation on non-socket */ + js_export_const(EDESTADDRREQ); /* Destination address required */ + js_export_const(EMSGSIZE); /* Message too long */ + js_export_const(EPROTOTYPE); /* Protocol wrong type for socket */ + js_export_const(ENOPROTOOPT); /* Protocol not available */ + js_export_const(EPROTONOSUPPORT);/* Protocol not supported */ + js_export_const(ESOCKTNOSUPPORT);/* Socket type not supported */ + js_export_const(EOPNOTSUPP); /* Operation not supported on transport endpoint */ + js_export_const(EPFNOSUPPORT); /* Protocol family not supported */ + js_export_const(EAFNOSUPPORT); /* Address family not supported by protocol */ + js_export_const(EADDRINUSE); /* Address already in use */ + js_export_const(EADDRNOTAVAIL); /* Cannot assign requested address */ + js_export_const(ENETDOWN); /* Network is down */ + js_export_const(ENETUNREACH); /* Network is unreachable */ + js_export_const(ENETRESET); /* Network dropped connection because of reset */ + js_export_const(ECONNABORTED); /* Software caused connection abort */ + js_export_const(ECONNRESET); /* Connection reset by peer */ + js_export_const(ENOBUFS); /* No buffer space available */ + js_export_const(EISCONN); /* Transport endpoint is already connected */ + js_export_const(ENOTCONN); /* Transport endpoint is not connected */ + js_export_const(ESHUTDOWN); /* Cannot send after transport endpoint shutdown */ + js_export_const(ETOOMANYREFS); /* Too many references: cannot splice */ + js_export_const(ETIMEDOUT); /* Connection timed out */ + js_export_const(ECONNREFUSED); /* Connection refused */ + js_export_const(EHOSTDOWN); /* Host is down */ + js_export_const(EHOSTUNREACH); /* No route to host */ + js_export_const(EALREADY); /* Operation already in progress */ + js_export_const(EINPROGRESS); /* Operation now in progress */ + js_export_const(ESTALE); /* Stale file handle */ + js_export_const(EDQUOT); /* Quota exceeded */ + js_export_const(ECANCELED); /* Operation Canceled */ + js_export_const(EOWNERDEAD); /* Owner died */ + js_export_const(ENOTRECOVERABLE);/* State not recoverable */ #if !OSS_PLATFORM_MAC_OS_X - CONST_EXPORT(ERFKILL); /* Operation not possible due to RF-kill */ - CONST_EXPORT(EHWPOISON); /* Memory page has hardware error */ - CONST_EXPORT(ENOKEY); /* Required key not available */ - CONST_EXPORT(EKEYEXPIRED); /* Key has expired */ - CONST_EXPORT(EKEYREVOKED); /* Key has been revoked */ - CONST_EXPORT(EKEYREJECTED); /* Key was rejected by service */ - CONST_EXPORT(ENOMEDIUM); /* No medium found */ - CONST_EXPORT(EMEDIUMTYPE); /* Wrong medium type */ - CONST_EXPORT(ECHRNG); /* Channel number out of range */ - CONST_EXPORT(EL2NSYNC); /* Level 2 not synchronized */ - CONST_EXPORT(EL3HLT); /* Level 3 halted */ - CONST_EXPORT(EL3RST); /* Level 3 reset */ - CONST_EXPORT(ELNRNG); /* Link number out of range */ - CONST_EXPORT(EUNATCH); /* Protocol driver not attached */ - CONST_EXPORT(ENOCSI); /* No CSI structure available */ - CONST_EXPORT(EL2HLT); /* Level 2 halted */ - CONST_EXPORT(EBADE); /* Invalid exchange */ - CONST_EXPORT(EBADR); /* Invalid request descriptor */ - CONST_EXPORT(EXFULL); /* Exchange full */ - CONST_EXPORT(ENOANO); /* No anode */ - CONST_EXPORT(EBADRQC); /* Invalid request code */ - CONST_EXPORT(EBADSLT); /* Invalid slot */ - CONST_EXPORT(EDEADLOCK); /* Resource deadlock would occur */ - CONST_EXPORT(EBFONT); /* Bad font file format */ - CONST_EXPORT(ENONET); /* Machine is not on the network */ - CONST_EXPORT(ENOPKG); /* Package not installed */ - CONST_EXPORT(EADV); /* Advertise error */ - CONST_EXPORT(ESRMNT); /* Srmount error */ - CONST_EXPORT(ECOMM); /* Communication error on send */ - CONST_EXPORT(EDOTDOT); /* RFS specific error */ - CONST_EXPORT(ENOTUNIQ); /* Name not unique on network */ - CONST_EXPORT(EBADFD); /* File descriptor in bad state */ - CONST_EXPORT(EREMCHG); /* Remote address changed */ - CONST_EXPORT(ELIBACC); /* Can not access a needed shared library */ - CONST_EXPORT(ELIBBAD); /* Accessing a corrupted shared library */ - CONST_EXPORT(ELIBSCN); /* lib section in a.out corrupted */ - CONST_EXPORT(ELIBMAX); /* Attempting to link in too many shared libraries */ - CONST_EXPORT(ELIBEXEC); /* Cannot exec a shared library directly */ - CONST_EXPORT(ERESTART); /* Interrupted system call should be restarted */ - CONST_EXPORT(ESTRPIPE); /* Streams pipe error */ - CONST_EXPORT(EUCLEAN); /* Structure needs cleaning */ - CONST_EXPORT(ENOTNAM); /* Not a XENIX named type file */ - CONST_EXPORT(ENAVAIL); /* No XENIX semaphores available */ - CONST_EXPORT(EISNAM); /* Is a named type file */ - CONST_EXPORT(EREMOTEIO); /* Remote I/O error */ + js_export_const(ERFKILL); /* Operation not possible due to RF-kill */ + js_export_const(EHWPOISON); /* Memory page has hardware error */ + js_export_const(ENOKEY); /* Required key not available */ + js_export_const(EKEYEXPIRED); /* Key has expired */ + js_export_const(EKEYREVOKED); /* Key has been revoked */ + js_export_const(EKEYREJECTED); /* Key was rejected by service */ + js_export_const(ENOMEDIUM); /* No medium found */ + js_export_const(EMEDIUMTYPE); /* Wrong medium type */ + js_export_const(ECHRNG); /* Channel number out of range */ + js_export_const(EL2NSYNC); /* Level 2 not synchronized */ + js_export_const(EL3HLT); /* Level 3 halted */ + js_export_const(EL3RST); /* Level 3 reset */ + js_export_const(ELNRNG); /* Link number out of range */ + js_export_const(EUNATCH); /* Protocol driver not attached */ + js_export_const(ENOCSI); /* No CSI structure available */ + js_export_const(EL2HLT); /* Level 2 halted */ + js_export_const(EBADE); /* Invalid exchange */ + js_export_const(EBADR); /* Invalid request descriptor */ + js_export_const(EXFULL); /* Exchange full */ + js_export_const(ENOANO); /* No anode */ + js_export_const(EBADRQC); /* Invalid request code */ + js_export_const(EBADSLT); /* Invalid slot */ + js_export_const(EDEADLOCK); /* Resource deadlock would occur */ + js_export_const(EBFONT); /* Bad font file format */ + js_export_const(ENONET); /* Machine is not on the network */ + js_export_const(ENOPKG); /* Package not installed */ + js_export_const(EADV); /* Advertise error */ + js_export_const(ESRMNT); /* Srmount error */ + js_export_const(ECOMM); /* Communication error on send */ + js_export_const(EDOTDOT); /* RFS specific error */ + js_export_const(ENOTUNIQ); /* Name not unique on network */ + js_export_const(EBADFD); /* File descriptor in bad state */ + js_export_const(EREMCHG); /* Remote address changed */ + js_export_const(ELIBACC); /* Can not access a needed shared library */ + js_export_const(ELIBBAD); /* Accessing a corrupted shared library */ + js_export_const(ELIBSCN); /* lib section in a.out corrupted */ + js_export_const(ELIBMAX); /* Attempting to link in too many shared libraries */ + js_export_const(ELIBEXEC); /* Cannot exec a shared library directly */ + js_export_const(ERESTART); /* Interrupted system call should be restarted */ + js_export_const(ESTRPIPE); /* Streams pipe error */ + js_export_const(EUCLEAN); /* Structure needs cleaning */ + js_export_const(ENOTNAM); /* Not a XENIX named type file */ + js_export_const(ENAVAIL); /* No XENIX semaphores available */ + js_export_const(EISNAM); /* Is a named type file */ + js_export_const(EREMOTEIO); /* Remote I/O error */ #endif - return exports; + js_export_finalize(); } JS_REGISTER_MODULE(Error); diff --git a/src/js/modules/esl/esl_connection.cpp b/src/js/modules/esl/esl_connection.cpp index f1f6631351..7315f1b4b6 100644 --- a/src/js/modules/esl/esl_connection.cpp +++ b/src/js/modules/esl/esl_connection.cpp @@ -57,15 +57,15 @@ ESLConnectionObject::~ESLConnectionObject() JS_CONSTRUCTOR_IMPL(ESLConnectionObject) { ESLConnectionObject* obj = new ESLConnectionObject(); - obj->Wrap(js_method_arg_self()); - return js_method_arg_self(); + obj->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(ESLConnectionObject::connect) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(3); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(3); js_method_arg_assert_string(0); js_method_arg_assert_uint32(1); js_method_arg_assert_string(2); @@ -76,171 +76,182 @@ JS_METHOD_IMPL(ESLConnectionObject::connect) OSS_LOG_INFO("Connecting to " << host << ":" << port); - return JSBoolean(pObject->_connection->connect(host, port, password)); + js_method_set_return_boolean(pObject->_connection->connect(host, port, password)); } JS_METHOD_IMPL(ESLConnectionObject::getInfo) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); ESLEvent::Ptr pResponse = pObject->_connection->getInfo(); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::send) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(1); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(1); std::string cmd = js_method_arg_as_std_string(0); - return JSBoolean(pObject->_connection->send(cmd)); + js_method_set_return_boolean(pObject->_connection->send(cmd)); } JS_METHOD_IMPL(ESLConnectionObject::sendRecv) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(1); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(1); std::string cmd = js_method_arg_as_std_string(0); ESLEvent::Ptr pResponse = pObject->_connection->sendRecv(cmd); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::api) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(2); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(2); std::string cmd = js_method_arg_as_std_string(0); std::string arg = js_method_arg_as_std_string(1); ESLEvent::Ptr pResponse = pObject->_connection->api(cmd, arg); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::bgapi) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(3); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(3); std::string cmd = js_method_arg_as_std_string(0); std::string arg = js_method_arg_as_std_string(1); std::string uuid = js_method_arg_as_std_string(2); ESLEvent::Ptr pResponse = pObject->_connection->bgapi(cmd, arg, uuid); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::sendEvent) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(1); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(1); ESLEventObject* pEvent = js_method_arg_as_esl_event(0); if (!pEvent) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } ESLEvent::Ptr pResponse = pObject->_connection->sendEvent(pEvent->_event); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::sendMsg) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(2); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(2); ESLEventObject* pEvent = js_method_arg_as_esl_event(0); std::string uuid = js_method_arg_as_std_string(1); if (!pEvent) { - return JSFalse; + js_method_set_return_false(); + return; } - return JSBoolean(pObject->_connection->sendMsg(pEvent->_event, uuid)); + js_method_set_return_boolean(pObject->_connection->sendMsg(pEvent->_event, uuid)); } JS_METHOD_IMPL(ESLConnectionObject::recvEvent) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); ESLEvent::Ptr pResponse = pObject->_connection->recvEvent(); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::recvEventTimed) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(1); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(1); int timeout = js_method_arg_as_int32(0); ESLEvent::Ptr pResponse = pObject->_connection->recvEventTimed(timeout); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::filter) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(2); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(2); std::string header = js_method_arg_as_std_string(0); std::string value = js_method_arg_as_std_string(1); ESLEvent::Ptr pResponse = pObject->_connection->filter(header, value); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::events) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(1); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(1); std::string value = js_method_arg_as_std_string(0); - return JSBoolean(pObject->_connection->events("json", value)); + js_method_set_return_boolean(pObject->_connection->events("json", value)); } JS_METHOD_IMPL(ESLConnectionObject::execute) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - js_method_arg_assert_size_gteq(3); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_args_assert_size_gteq(3); std::string app = js_method_arg_as_std_string(0); std::string arg = js_method_arg_as_std_string(1); std::string uuid = js_method_arg_as_std_string(2); ESLEvent::Ptr pResponse = pObject->_connection->execute(app, arg, uuid); if (!pResponse) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pResponse->data()); + js_method_set_return_string(pResponse->data()); } JS_METHOD_IMPL(ESLConnectionObject::disconnect) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - return JSBoolean(pObject->_connection->disconnect()); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_set_return_boolean(pObject->_connection->disconnect()); } JS_METHOD_IMPL(ESLConnectionObject::connected) { - ESLConnectionObject* pObject = js_method_arg_unwrap_self(ESLConnectionObject); - return JSBoolean(pObject->_connection->connected()); + ESLConnectionObject* pObject = js_method_unwrap_self(ESLConnectionObject); + js_method_set_return_boolean(pObject->_connection->connected()); } JS_EXPORTS_INIT() diff --git a/src/js/modules/esl/esl_event.cpp b/src/js/modules/esl/esl_event.cpp index 1060d54941..7099f8c587 100644 --- a/src/js/modules/esl/esl_event.cpp +++ b/src/js/modules/esl/esl_event.cpp @@ -54,47 +54,49 @@ ESLEventObject::~ESLEventObject() JS_CONSTRUCTOR_IMPL(ESLEventObject) { ESLEventObject* obj = new ESLEventObject(); - obj->Wrap(js_method_arg_self()); - return js_method_arg_self(); + obj->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(ESLEventObject::create) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); - js_method_arg_assert_size_eq(2); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); + js_method_args_assert_size_eq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); std::string type = js_method_arg_as_std_string(0); std::string subClass = js_method_arg_as_std_string(0); - return JSBoolean(pObject->_event->create(type, subClass)); + js_method_set_return_boolean(pObject->_event->create(type, subClass)); } JS_METHOD_IMPL(ESLEventObject::data) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pObject->_event->data()); + js_method_set_return_string(pObject->_event->data()); } JS_METHOD_IMPL(ESLEventObject::getHeader) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_string(0); std::string name = js_method_arg_as_std_string(0); uint32_t index = 0; - if (js_method_arg_length() > 1) + if (js_method_args_length() > 1) { js_method_arg_assert_uint32(1); index = js_method_arg_as_uint32(1); @@ -102,172 +104,190 @@ JS_METHOD_IMPL(ESLEventObject::getHeader) std::string value; if (pObject->_event->getHeader(name, value, index)) { - return JSString(value); + js_method_set_return_string(value); + return; } - return JSUndefined(); + + js_method_set_return_undefined(); } JS_METHOD_IMPL(ESLEventObject::getBody) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } std::string body; if (pObject->_event->getBody(body)) { - return JSString(body); + js_method_set_return_string(body); + return; } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ESLEventObject::getEventName) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } std::string name; if (pObject->_event->getEventName(name)) { - return JSString(name); + js_method_set_return_string(name); + return; } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ESLEventObject::setBody) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); - return JSBoolean(pObject->_event->setBody(value)); + js_method_set_return_boolean(pObject->_event->setBody(value)); } JS_METHOD_IMPL(ESLEventObject::addHeader) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - js_method_arg_assert_size_gteq(2); + js_method_args_assert_size_gteq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); std::string name = js_method_arg_as_std_string(0); std::string value = js_method_arg_as_std_string(1); - return JSBoolean(pObject->_event->addHeader(name, value)); + js_method_set_return_boolean(pObject->_event->addHeader(name, value)); } JS_METHOD_IMPL(ESLEventObject::pushHeader) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - js_method_arg_assert_size_gteq(2); + js_method_args_assert_size_gteq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); std::string name = js_method_arg_as_std_string(0); std::string value = js_method_arg_as_std_string(1); - return JSBoolean(pObject->_event->pushHeader(name, value)); + js_method_set_return_boolean(pObject->_event->pushHeader(name, value)); } JS_METHOD_IMPL(ESLEventObject::unshiftHeader) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - js_method_arg_assert_size_gteq(2); + js_method_args_assert_size_gteq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); std::string name = js_method_arg_as_std_string(0); std::string value = js_method_arg_as_std_string(1); - return JSBoolean(pObject->_event->unshiftHeader(name, value)); + js_method_set_return_boolean(pObject->_event->unshiftHeader(name, value)); } JS_METHOD_IMPL(ESLEventObject::removeHeader) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_string(0); std::string name = js_method_arg_as_std_string(0); - return JSBoolean(pObject->_event->removeHeader(name)); + js_method_set_return_boolean(pObject->_event->removeHeader(name)); } JS_METHOD_IMPL(ESLEventObject::first) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } const char* iter = pObject->_event->first(); if (iter) { - return JSString(iter); + js_method_set_return_string(iter); + return; } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ESLEventObject::next) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } const char* iter = pObject->_event->next(); if (iter) { - return JSString(iter); + js_method_set_return_string(iter); + return; } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ESLEventObject::setPriority) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - js_method_arg_assert_size_gteq(1); + js_method_args_assert_size_gteq(1); js_method_arg_assert_int32(0); int32_t priority = js_method_arg_as_int32(0); if (priority > ESLEvent::EVENT_PRIORITY_HIGH) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - return JSBoolean(pObject->_event->setPriority((ESLEvent::Priority)priority)); + js_method_set_return_boolean(pObject->_event->setPriority((ESLEvent::Priority)priority)); } JS_METHOD_IMPL(ESLEventObject::isValid) { - ESLEventObject* pObject = js_method_arg_unwrap_self(ESLEventObject); + ESLEventObject* pObject = js_method_unwrap_self(ESLEventObject); if (!pObject->_event) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - return JSBoolean(pObject->_event->isValid()); + js_method_set_return_boolean(pObject->_event->isValid()); } JS_EXPORTS_INIT() diff --git a/src/js/modules/examples/cpp_rpc_tester.cpp b/src/js/modules/examples/cpp_rpc_tester.cpp index d2fd197d0e..0aef68da3f 100644 --- a/src/js/modules/examples/cpp_rpc_tester.cpp +++ b/src/js/modules/examples/cpp_rpc_tester.cpp @@ -53,13 +53,13 @@ static void test_ping(OSS::JS::JSIsolate::Ptr pIsolate) JS_METHOD_IMPL(start_test) { new boost::thread(test_ping, OSS::JS::JSIsolateManager::instance().getIsolate()); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(parse_user_data) { - std::string* userData = js_method_arg_unwrap_object(std::string, 0); - return JSString(userData->c_str()); + std::string* userData = js_method_unwrap_object(std::string, 0); + js_method_set_return_string( *userData ); } JS_EXPORTS_INIT() diff --git a/src/js/modules/file/file.cpp b/src/js/modules/file/file.cpp index 4b56f468ec..0a653ea7cd 100644 --- a/src/js/modules/file/file.cpp +++ b/src/js/modules/file/file.cpp @@ -69,212 +69,220 @@ FileObject::~FileObject() JS_CONSTRUCTOR_IMPL(FileObject) { FileObject* pFile = new FileObject(); - pFile->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pFile->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(FileObject::_fopen) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); std::string file = js_method_arg_as_std_string(0); std::string options = js_method_arg_as_std_string(1); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); + FileObject* pFile = js_method_unwrap_self(FileObject); pFile->_pFile = ::fopen(file.c_str(), options.c_str()); - return JSBoolean(pFile->_pFile != 0); + js_method_set_return_boolean(pFile->_pFile != 0); } JS_METHOD_IMPL(FileObject::_fmemopen) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_string(1); int len = js_method_arg_as_int32(0); std::string options = js_method_arg_as_std_string(1); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(len, "Invalid Argument"); - js_assert(pFile->_pFile, "Invalid Argument"); - JSValueHandle result = BufferObject::createNew(len); - BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject()); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(len, "Invalid Argument"); + js_method_assert(pFile->_pFile, "Invalid Argument"); + JSValueHandle result = BufferObject::createNew(js_method_isolate(), len); + BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject(js_method_context()).ToLocalChecked()); ByteArray& buf = pBuffer->buffer(); pFile->_pFile = ::fmemopen(buf.data(), buf.size(), options.c_str()); - return JSBoolean(pFile->_pFile != 0); + js_method_set_return_boolean(pFile->_pFile != 0); } JS_METHOD_IMPL(FileObject::_fclose) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); + FileObject* pFile = js_method_unwrap_self(FileObject); if (pFile->_pFile) { FILE* pHandle = pFile->_pFile; pFile->_pFile = 0; - return JSInt32(::fclose(pHandle)); + js_method_set_return_handle(js_method_int32(::fclose(pHandle))); + return; } - return JSInt32(EOF); + js_method_set_return_handle(js_method_int32(EOF)); } JS_METHOD_IMPL(FileObject::_fseek) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_int32(0); js_method_arg_assert_int32(1); int32_t offset = js_method_arg_as_int32(0); int32_t whence = js_method_arg_as_int32(1); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid Argument"); - return JSInt32( ::fseek(pFile->_pFile, offset, whence) ); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid Argument"); + js_method_set_return_handle(js_method_int32( ::fseek(pFile->_pFile, offset, whence) ) ) ; } JS_METHOD_IMPL(FileObject::_rewind) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid Argument"); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid Argument"); ::rewind(pFile->_pFile); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(FileObject::_fflush) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid Argument"); - return JSInt32(::fflush(pFile->_pFile)); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid Argument"); + js_method_set_return_handle(js_method_int32(::fflush(pFile->_pFile))); } JS_METHOD_IMPL(FileObject::_feof) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid Argument"); - return JSBoolean(::feof(pFile->_pFile) != 0); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid Argument"); + js_method_set_return_boolean(::feof(pFile->_pFile) != 0); } JS_METHOD_IMPL(FileObject::_ferror) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid Argument"); - return JSInt32(::ferror(pFile->_pFile)); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid Argument"); + js_method_set_return_handle(js_method_int32(::ferror(pFile->_pFile))); } JS_METHOD_IMPL(FileObject::_fread) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); int len = js_method_arg_as_int32(0); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(len, "Invalid Argument"); - js_assert(pFile->_pFile, "Invalid Argument"); - JSValueHandle result = BufferObject::createNew(len); - BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject()); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(len, "Invalid Argument"); + js_method_assert(pFile->_pFile, "Invalid Argument"); + JSValueHandle result = BufferObject::createNew(js_method_isolate(), len); + BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject(js_method_context()).ToLocalChecked()); ByteArray& buf = pBuffer->buffer(); std::size_t ret = ::fread(buf.data(), buf.size(), len, pFile->_pFile); if (!ret) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return result; + js_method_set_return_handle( result ); } JS_METHOD_IMPL(FileObject::_fwrite) { - js_method_arg_assert_size_eq(1); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid Argument"); + js_method_args_assert_size_eq(1); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid Argument"); if (js_method_arg_is_string(0)) { std::string data = js_method_arg_as_std_string(0); - return JSInt32(::fwrite(data.data(), 1, data.size(), pFile->_pFile)); + js_method_set_return_handle(js_method_int32(::fwrite(data.data(), 1, data.size(), pFile->_pFile))); + return; } else if (js_method_arg_is_array(0)) { JSArrayHandle args1 = js_method_arg_as_array(0); ByteArray bytes; - if (!js_int_array_to_byte_array(args1, bytes)) + if (!js_int_array_to_byte_array(js_method_isolate(), args1, bytes)) { - return JSInt32(-1); + js_method_set_return_handle(js_method_int32(-1)); + return; } - return JSInt32(::fwrite(bytes.data(), 1, bytes.size(), pFile->_pFile)); + js_method_set_return_handle(js_method_int32(::fwrite(bytes.data(), 1, bytes.size(), pFile->_pFile))); + return; } else if (js_method_arg_is_buffer(0)) { - BufferObject* pBuffer = js_method_arg_unwrap_object(BufferObject, 0); - return JSInt32(::fwrite(pBuffer->buffer().data(), 1, pBuffer->buffer().size(), pFile->_pFile)); + BufferObject* pBuffer = js_method_unwrap_object(BufferObject, 0); + js_method_set_return_handle(js_method_int32(::fwrite(pBuffer->buffer().data(), 1, pBuffer->buffer().size(), pFile->_pFile))); + return; } - return JSException("Invalid Argument"); + js_method_throw("Invalid Argument"); } JS_METHOD_IMPL(FileObject::_fgets) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); int len = js_method_arg_as_int32(0); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(len, "Invalid Argument"); - js_assert(pFile->_pFile, "Invalid Argument"); - JSValueHandle result = BufferObject::createNew(len); - BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject()); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(len, "Invalid Argument"); + js_method_assert(pFile->_pFile, "Invalid Argument"); + JSValueHandle result = BufferObject::createNew(js_method_isolate(), len); + BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject(js_method_context()).ToLocalChecked()); ByteArray& buf = pBuffer->buffer(); char* line = ::fgets((char*)buf.data(), buf.size(), pFile->_pFile); if (!line) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } buf.resize(strlen(line)); - return result; + js_method_set_return_handle(result); } JS_METHOD_IMPL(FileObject::_fileno) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid State"); - return JSInt32(::fileno(pFile->_pFile)); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid State"); + js_method_set_return_handle(js_method_int32(::fileno(pFile->_pFile))); } JS_METHOD_IMPL(FileObject::_fputc) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid State"); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid State"); int c = js_method_arg_as_int32(0); - return JSInt32(::fputc(c, pFile->_pFile)); + js_method_set_return_handle(js_method_int32(::fputc(c, pFile->_pFile))); } JS_METHOD_IMPL(FileObject::_fputs) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string data = js_method_arg_as_std_string(0); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid State"); - return JSInt32(::fputs(data.c_str(), pFile->_pFile)); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid State"); + js_method_set_return_handle(js_method_int32(::fputs(data.c_str(), pFile->_pFile))); } JS_METHOD_IMPL(FileObject::_ftell) { - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid State"); - return JSInt32(::ftell(pFile->_pFile)); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid State"); + js_method_set_return_handle(js_method_int32(::ftell(pFile->_pFile))); } JS_METHOD_IMPL(FileObject::_flock) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int32_t operation = js_method_arg_as_int32(0); - FileObject* pFile = js_method_arg_unwrap_self(FileObject); - js_assert(pFile->_pFile, "Invalid State"); - return JSInt32(::flock(::fileno(pFile->_pFile), operation)); + FileObject* pFile = js_method_unwrap_self(FileObject); + js_method_assert(pFile->_pFile, "Invalid State"); + js_method_set_return_handle(js_method_int32(::flock(::fileno(pFile->_pFile), operation))); } JS_EXPORTS_INIT() { js_export_class(FileObject); - js_export_global_constructor("File", FileObject::_constructor); + JSFunctionHandle constructor = JSFunctionHandle::New( js_method_isolate(), FileObject::_constructor ); + js_export_global_constructor("File", constructor); LINE_MAX_LEN = sysconf(_SC_LINE_MAX); js_export_const(SEEK_SET); diff --git a/src/js/modules/filesystem/filesystem.cpp b/src/js/modules/filesystem/filesystem.cpp index 7fb05c496c..ce942ddfcd 100644 --- a/src/js/modules/filesystem/filesystem.cpp +++ b/src/js/modules/filesystem/filesystem.cpp @@ -23,64 +23,64 @@ JS_METHOD_IMPL(__exists) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string filename = js_method_arg_as_std_string(0); boost::filesystem::path file(filename.c_str()); - return JSBoolean(boost::filesystem::exists(file)); + js_method_set_return_boolean(boost::filesystem::exists(file)); } JS_METHOD_IMPL(__remove) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string filename = js_method_arg_as_std_string(0); boost::system::error_code ec; boost::filesystem::path file(filename.c_str()); - return JSBoolean(boost::filesystem::remove(file, ec)); + js_method_set_return_boolean(boost::filesystem::remove(file, ec)); } JS_METHOD_IMPL(__remove_all) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string filename = js_method_arg_as_std_string(0); boost::system::error_code ec; boost::filesystem::path file(filename.c_str()); - return JSUInt32(boost::filesystem::remove_all(file, ec)); + js_method_set_return_handle(js_method_uint32(boost::filesystem::remove_all(file, ec))); } JS_METHOD_IMPL(__chdir) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string dir = js_method_arg_as_std_string(0); - return JSInt32(chdir(dir.c_str())); + js_method_set_return_handle(js_method_int32(chdir(dir.c_str()))); } JS_METHOD_IMPL(__current_path) { boost::filesystem::path path = boost::filesystem::current_path(); - return JSString(OSS::boost_path(path).c_str()); + js_method_set_return_string(OSS::boost_path(path).c_str()); } JS_METHOD_IMPL(__is_directory) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string dir = js_method_arg_as_std_string(0); boost::filesystem::path path(dir.c_str()); - return JSBoolean(boost::filesystem::is_directory(path)); + js_method_set_return_boolean(boost::filesystem::is_directory(path)); } JS_METHOD_IMPL(__get_directory) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string pathStr = js_method_arg_as_std_string(0); boost::filesystem::path path(pathStr.c_str()); boost::filesystem::path parent = path.parent_path(); - return JSString(OSS::boost_path(parent).c_str()); + js_method_set_return_string(OSS::boost_path(parent).c_str()); } JS_EXPORTS_INIT() diff --git a/src/js/modules/fork/fork.cpp b/src/js/modules/fork/fork.cpp index 0a27e85d0c..be53fcc819 100644 --- a/src/js/modules/fork/fork.cpp +++ b/src/js/modules/fork/fork.cpp @@ -25,17 +25,17 @@ JS_METHOD_IMPL(__fork) { - return JSInt32(fork()); + js_method_set_return_handle(js_method_int32(fork())); } JS_METHOD_IMPL(__wait) { int status = 0; pid_t pid = ::wait(&status); - JSObjectHandle result = JSObject(); - result->Set(JSLiteral("pid"), JSUInt32(pid)); - result->Set(JSLiteral("status"), JSUInt32(status)); - return result; + JSObjectHandle result = js_method_object(); + result->Set(js_method_context(),js_method_string("pid"), js_method_uint32(pid)); + result->Set(js_method_context(),js_method_string("status"), js_method_uint32(status)); + js_method_set_return_handle(result); } JS_EXPORTS_INIT() diff --git a/src/js/modules/getopt/getopt.cpp b/src/js/modules/getopt/getopt.cpp index 470bf1b053..d7732fc300 100644 --- a/src/js/modules/getopt/getopt.cpp +++ b/src/js/modules/getopt/getopt.cpp @@ -9,59 +9,61 @@ static char** gArgv = 0; JS_METHOD_IMPL(__getopt) { - js_method_arg_declare_string(optstring, 0); - return v8::Uint32::New(::getopt(gArgc, gArgv, optstring.c_str())); + js_method_declare_string(optstring, 0); + js_method_set_return_handle(js_method_uint32(::getopt(gArgc, gArgv, optstring.c_str()))); } -static v8::Handle __optind_get(v8::Local property, const v8::AccessorInfo& info) +JS_ACCESSOR_GETTER_IMPL(__optind_get) { - return v8::Integer::New(optind); + js_method_set_return_integer(optind); } -void __optind_set(v8::Local property, v8::Local value, const v8::AccessorInfo& info) +JS_ACCESSOR_SETTER_IMPL(__optind_set) { - optind = value->Int32Value(); + optind = value->Int32Value(js_method_context()).ToChecked(); } -static v8::Handle __opterr_get(v8::Local property, const v8::AccessorInfo& info) +JS_ACCESSOR_GETTER_IMPL(__opterr_get) { - return v8::Integer::New(opterr); + js_method_set_return_integer(opterr); } -void __opterr_set(v8::Local property, v8::Local value, const v8::AccessorInfo& info) +JS_ACCESSOR_SETTER_IMPL(__opterr_set) { - opterr = value->Int32Value(); + opterr = value->Int32Value(js_method_context()).ToChecked(); } -static v8::Handle __optarg_get(v8::Local property, const v8::AccessorInfo& info) +JS_ACCESSOR_GETTER_IMPL(__optarg_get) { - return v8::String::New(optarg); + js_method_set_return_string(optarg); } -static v8::Handle __optopt_get(v8::Local property, const v8::AccessorInfo& info) +JS_ACCESSOR_GETTER_IMPL(__optopt_get) { - return v8::Uint32::New(optopt); + js_method_set_return_integer(optopt); } -static v8::Handle init_exports(const v8::Arguments& args) -{ - v8::Local exports = v8::Local::New(v8::Object::New()); - +JS_EXPORTS_INIT() +{ OSS::OSS_argv(&gArgc, &gArgv); optind = 2; - exports->Set(v8::String::New("argc"), v8::Uint32::New(gArgc)); - v8::Local argv = v8::Array::New(gArgc); + + js_export_uint32( "argc", gArgc); + + JSLocalArrayHandle argv = js_method_array(gArgc); for (int i = 0; i < gArgc; i++) { - argv->Set(i, v8::String::New(gArgv[i])); + argv->Set( js_method_context(), i, js_method_string(gArgv[i]) ); } - exports->Set(v8::String::New("argv"), argv); - exports->Set(v8::String::New("getopt"), v8::FunctionTemplate::New(__getopt)->GetFunction()); - exports->SetAccessor(v8::String::New("opterr"), __opterr_get, __opterr_set); - exports->SetAccessor(v8::String::New("optind"), __optind_get, __optind_set); - exports->SetAccessor(v8::String::New("optarg"), __optarg_get, 0); - exports->SetAccessor(v8::String::New("optopt"), __optopt_get, 0); - return exports; + + js_export_value( "argv", argv); + js_export_method("getopt", __getopt ); + js_export_accessor("opterr", __opterr_get, __opterr_set); + js_export_accessor("optind", __optind_get, __optind_set); + js_export_accessor("optarg", __optarg_get, NULL); + js_export_accessor("optopt", __optopt_get, NULL); + + js_export_finalize(); } JS_REGISTER_MODULE(GetOpt); \ No newline at end of file diff --git a/src/js/modules/http/http_client.cpp b/src/js/modules/http/http_client.cpp index 059b89b441..50a072b701 100644 --- a/src/js/modules/http/http_client.cpp +++ b/src/js/modules/http/http_client.cpp @@ -31,7 +31,7 @@ using OSS::JS::JSObjectWrap; -#define assert_session(Self) if (!Self->_session) { js_throw("Client session has been disposed"); } +#define assert_session(Self) if (!Self->_session) { js_method_throw("Client session has been disposed"); } // // Define the Interface // @@ -84,7 +84,7 @@ HttpClientObject::~HttpClientObject() JS_CONSTRUCTOR_IMPL(HttpClientObject) { - js_method_arg_declare_bool(isSecure, 0); + js_method_declare_bool(isSecure, 0); HttpClientObject* pClient = 0; try { @@ -94,108 +94,108 @@ JS_CONSTRUCTOR_IMPL(HttpClientObject) { if (isSecure) { - js_throw("Unable to create secure client. Check SSL context"); + js_method_throw("Unable to create secure client. Check SSL context"); } else { - js_throw(e.message().c_str()); + js_method_throw(e.message().c_str()); } } - pClient->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pClient->Wrap(js_method_self()); + js_method_set_return_handle(js_method_self()); } JS_METHOD_IMPL(HttpClientObject::setHost) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pClient->_session->setHost(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::getHost) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - return JSString(pClient->_session->getHost()); + js_method_set_return_string(pClient->_session->getHost()); } JS_METHOD_IMPL(HttpClientObject::setPort) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t value = js_method_arg_as_uint32(0); pClient->_session->setPort(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::getPort) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - return JSUInt32(pClient->_session->getPort()); + js_method_set_return_handle(js_method_uint32(pClient->_session->getPort())); } JS_METHOD_IMPL(HttpClientObject::setProxyHost) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pClient->_session->setProxyHost(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::setProxyPort) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t value = js_method_arg_as_uint32(0); pClient->_session->setProxyPort(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::getProxyHost) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - return JSString(pClient->_session->getProxyHost()); + js_method_set_return_string(pClient->_session->getProxyHost()); } JS_METHOD_IMPL(HttpClientObject::getProxyPort) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - return JSUInt32(pClient->_session->getProxyPort()); + js_method_set_return_handle(js_method_uint32(pClient->_session->getProxyPort())); } JS_METHOD_IMPL(HttpClientObject::setKeepAliveTimeout) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t seconds = js_method_arg_as_uint32(0); Poco::Timespan timespan; timespan.assign(seconds, 0); pClient->_session->setKeepAliveTimeout(timespan); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::getKeepAliveTimeout) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); const Poco::Timespan& timespan = pClient->_session->getKeepAliveTimeout(); - return JSUInt32(timespan.milliseconds() * 1000); + js_method_set_return_handle(js_method_uint32(timespan.milliseconds() * 1000)); } class RequestSender : public Poco::Runnable @@ -243,13 +243,13 @@ class RequestSender : public Poco::Runnable JS_METHOD_IMPL(HttpClientObject::sendRequest) { - js_method_arg_declare_self(HttpClientObject, self); + js_method_declare_self(HttpClientObject, self); assert_session(self); - js_method_arg_declare_external_object(HttpRequestObject, pRequest, 0); + js_method_declare_external_object(HttpRequestObject, pRequest, 0); if (self->getEventFd() == -1) { - js_throw("Event Emitter FD not set"); + js_method_throw("Event Emitter FD not set"); } RequestSender* runnable = new RequestSender(self, pRequest, self->getEventFd()); @@ -261,14 +261,14 @@ JS_METHOD_IMPL(HttpClientObject::sendRequest) catch(const NoThreadAvailableException& e) { delete runnable; - js_throw(e.message().c_str()); + js_method_throw(e.message().c_str()); } catch(...) { delete runnable; - js_throw("Unknown Exception"); + js_method_throw("Unknown Exception"); } - return JSUndefined(); + js_method_set_return_undefined(); } @@ -315,13 +315,13 @@ class ResponseReceiver : public Poco::Runnable JS_METHOD_IMPL(HttpClientObject::receiveResponse) { - js_method_arg_declare_self(HttpClientObject, self); + js_method_declare_self(HttpClientObject, self); assert_session(self); - js_method_arg_declare_external_object(HttpResponseObject, pResponse, 0); + js_method_declare_external_object(HttpResponseObject, pResponse, 0); if (self->getEventFd() == -1) { - js_throw("Event Emitter FD not set"); + js_method_throw("Event Emitter FD not set"); } ResponseReceiver* runnable = new ResponseReceiver(self, pResponse, self->getEventFd()); @@ -332,28 +332,28 @@ JS_METHOD_IMPL(HttpClientObject::receiveResponse) catch(const NoThreadAvailableException& e) { delete runnable; - js_throw(e.message().c_str()); + js_method_throw(e.message().c_str()); } catch(...) { delete runnable; - js_throw("Unknown Exception"); + js_method_throw("Unknown Exception"); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::connected) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - return JSBoolean(pClient->_session->connected()); + js_method_set_return_boolean(pClient->_session->connected()); } JS_METHOD_IMPL(HttpClientObject::secure) { - HttpClientObject* pClient = js_method_arg_unwrap_self(HttpClientObject); + HttpClientObject* pClient = js_method_unwrap_self(HttpClientObject); assert_session(pClient); - return JSBoolean(pClient->_isSecure); + js_method_set_return_boolean(pClient->_isSecure); } class ResponseReader : public Poco::Runnable @@ -399,10 +399,10 @@ class ResponseReader : public Poco::Runnable JS_METHOD_IMPL(HttpClientObject::read) { - js_method_arg_declare_self(HttpClientObject, self); + js_method_declare_self(HttpClientObject, self); assert_session(self); - js_method_arg_declare_external_object(BufferObject, buf, 0); - js_method_arg_declare_uint32(size, 1); + js_method_declare_external_object(BufferObject, buf, 0); + js_method_declare_uint32(size, 1); if (self->_input) { @@ -414,12 +414,12 @@ JS_METHOD_IMPL(HttpClientObject::read) catch(const NoThreadAvailableException& e) { delete runnable; - js_throw(e.message().c_str()); + js_method_throw(e.message().c_str()); } catch(...) { delete runnable; - js_throw("Unknown Exception"); + js_method_throw("Unknown Exception"); } } else @@ -428,41 +428,41 @@ JS_METHOD_IMPL(HttpClientObject::read) json.addString("Input Stream Not Set"); self->getIsolate()->eventLoop()->eventEmitter().emit(json); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::write) { - js_method_arg_declare_self(HttpClientObject, self); + js_method_declare_self(HttpClientObject, self); assert_session(self); - js_method_arg_declare_external_object(BufferObject, buf, 0); - js_method_arg_declare_uint32(size, 1); + js_method_declare_external_object(BufferObject, buf, 0); + js_method_declare_uint32(size, 1); if (self->_output) { std::ostream& strm = *self->_output; - return JSBoolean(!strm.write((char*)buf->buffer().data(), size).fail()); + js_method_set_return_boolean(!strm.write((char*)buf->buffer().data(), size).fail()); } - return JSBoolean(false); + js_method_set_return_false(); } JS_METHOD_IMPL(HttpClientObject::setEventFd) { - js_method_arg_declare_self(HttpClientObject, self); + js_method_declare_self(HttpClientObject, self); assert_session(self); - js_method_arg_declare_int32(fd, 0); + js_method_declare_int32(fd, 0); self->_eventFd = fd; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpClientObject::dispose) { - js_method_arg_declare_self(HttpClientObject, self); + js_method_declare_self(HttpClientObject, self); assert_session(self); delete self->_session; self->_session = 0; - return JSUndefined(); + js_method_set_return_undefined(); } JS_EXPORTS_INIT() diff --git a/src/js/modules/http/http_parser.cpp b/src/js/modules/http/http_parser.cpp index ae37832321..6b6db0fc80 100644 --- a/src/js/modules/http/http_parser.cpp +++ b/src/js/modules/http/http_parser.cpp @@ -212,141 +212,148 @@ bool HttpParserObject::getHeaderAt(uint32_t index, std::string& name, std::strin JS_CONSTRUCTOR_IMPL(HttpParserObject) { HttpParserObject* pFile = new HttpParserObject(); - pFile->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pFile->Wrap(js_method_self()); + js_method_set_return_handle(js_method_self()); } JS_METHOD_IMPL(HttpParserObject::getMethod) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); if (pParser->getUrl().empty()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pParser->getMethod().c_str()); + js_method_set_return_string(pParser->getMethod().c_str()); } JS_METHOD_IMPL(HttpParserObject::getUrl) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); if (pParser->getUrl().empty()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pParser->getUrl().c_str()); + js_method_set_return_string(pParser->getUrl().c_str()); } JS_METHOD_IMPL(HttpParserObject::getStatus) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); if (pParser->getStatus().empty()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pParser->getStatus().c_str()); + js_method_set_return_string(pParser->getStatus().c_str()); } JS_METHOD_IMPL(HttpParserObject::getStatusCode) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); if (!pParser->getStatusCode()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSInt32(pParser->getStatusCode()); + js_method_set_return_handle(js_method_int32(pParser->getStatusCode())); } JS_METHOD_IMPL(HttpParserObject::getMajorVersion) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSInt32(pParser->getMajorVersion()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_handle(js_method_int32(pParser->getMajorVersion())); } JS_METHOD_IMPL(HttpParserObject::getMinorVersion) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSInt32(pParser->getMinorVersion()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_handle(js_method_int32(pParser->getMinorVersion())); } JS_METHOD_IMPL(HttpParserObject::getHeader) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_is_string(0); std::string header = js_method_arg_as_std_string(0); - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); std::string value; if (!pParser->getHeader(header, value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(value.c_str()); + js_method_set_return_string(value.c_str()); } JS_METHOD_IMPL(HttpParserObject::getHeaderCount) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSUInt32(pParser->getHeaderCount()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_handle(js_method_uint32(pParser->getHeaderCount())); } JS_METHOD_IMPL(HttpParserObject::getHeaderAt) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); uint32_t index = js_method_arg_as_uint32(0); - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); std::string name; std::string value; if (!pParser->getHeaderAt(index, name, value)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - JSLocalObjectHandle header = JSObject(); - header->Set(JSLiteral("header"), JSString(name.c_str())); - header->Set(JSLiteral("value"), JSString(value.c_str())); - return header; + JSLocalObjectHandle header = js_method_object(); + header->Set(js_method_context(),js_method_string("header"), js_method_string(name.c_str())); + header->Set(js_method_context(),js_method_string("value"), js_method_string(value.c_str())); + js_method_set_return_handle(header); } JS_METHOD_IMPL(HttpParserObject::getBody) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); if (pParser->getBody().empty()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(pParser->getBody().c_str()); + js_method_set_return_string(pParser->getBody().c_str()); } JS_METHOD_IMPL(HttpParserObject::isRequest) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSBoolean(pParser->isRequest()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_boolean(pParser->isRequest()); } JS_METHOD_IMPL(HttpParserObject::isReponse) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSBoolean(pParser->isResponse()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_boolean(pParser->isResponse()); } JS_METHOD_IMPL(HttpParserObject::isMessageComplete) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSBoolean(pParser->isMessageComplete()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_boolean(pParser->isMessageComplete()); } JS_METHOD_IMPL(HttpParserObject::isHeadersComplete) { - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSBoolean(pParser->isHeadersComplete()); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_boolean(pParser->isHeadersComplete()); } JS_METHOD_IMPL(HttpParserObject::parse) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_buffer(0); BufferObject* pBuffer = js_method_arg_as_buffer(0); - HttpParserObject* pParser = js_method_arg_unwrap_self(HttpParserObject); - return JSUInt32(http_parser_execute(&pParser->_parser, &_settings, (const char*)pBuffer->buffer().data(), pBuffer->buffer().size())); + HttpParserObject* pParser = js_method_unwrap_self(HttpParserObject); + js_method_set_return_handle(js_method_uint32(http_parser_execute(&pParser->_parser, &_settings, (const char*)pBuffer->buffer().data(), pBuffer->buffer().size()))); } JS_EXPORTS_INIT() diff --git a/src/js/modules/http/http_request.cpp b/src/js/modules/http/http_request.cpp index ddc0ed2ccc..89e425a9db 100644 --- a/src/js/modules/http/http_request.cpp +++ b/src/js/modules/http/http_request.cpp @@ -77,283 +77,285 @@ HttpRequestObject::~HttpRequestObject() JS_CONSTRUCTOR_IMPL(HttpRequestObject) { HttpRequestObject* pObject = new HttpRequestObject(); - pObject->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pObject->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(HttpRequestObject::setMethod) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_request->setMethod(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getMethod) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSString(pObject->_request->getMethod()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_string(pObject->_request->getMethod()); } JS_METHOD_IMPL(HttpRequestObject::setUri) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_request->setURI(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getUri) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSString(pObject->_request->getURI()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_string(pObject->_request->getURI()); } JS_METHOD_IMPL(HttpRequestObject::setHost) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_request->setHost(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getHost) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSString(pObject->_request->getHost()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_string(pObject->_request->getHost()); } JS_METHOD_IMPL(HttpRequestObject::setCookies) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_object(0); JSLocalObjectHandle obj = js_method_arg_as_object(0); - JSLocalArrayHandle properties = obj->GetPropertyNames(); + JSLocalArrayHandle properties = obj->GetPropertyNames(js_method_context()).ToLocalChecked(); Cookies cookies; for(uint32_t i = 0; i < properties->Length(); i++) { - JSLocalValueHandle name = properties->Get(i); - JSLocalValueHandle value = obj->Get(name); - cookies.add(js_handle_as_std_string(name), js_handle_as_std_string(value)); + JSLocalValueHandle name = properties->Get(js_method_context(),i).ToLocalChecked(); + JSLocalValueHandle value = obj->Get(js_method_context(),name).ToLocalChecked(); + cookies.add(js_method_handle_as_std_string(name), js_method_handle_as_std_string(value)); } pObject->_request->setCookies(cookies); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getCookies) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); Cookies cookies; pObject->_request->getCookies(cookies); if (cookies.empty()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - JSLocalObjectHandle obj = JSObject(); + JSLocalObjectHandle obj = js_method_object(); for (Cookies::ConstIterator iter = cookies.begin(); iter != cookies.end(); iter++) { - obj->Set(JSLiteral(iter->first.c_str()), JSString(iter->second)); + obj->Set(js_method_context(),js_method_string(iter->first.c_str()), js_method_string(iter->second)); } - return obj; + js_method_set_return_handle(obj); } JS_METHOD_IMPL(HttpRequestObject::hasCredentials) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSBoolean(pObject->_request->hasCredentials()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_boolean(pObject->_request->hasCredentials()); } JS_METHOD_IMPL(HttpRequestObject::getCredentials) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); if (!pObject->_request->hasCredentials()) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - JSLocalObjectHandle obj = JSObject(); + JSLocalObjectHandle obj = js_method_object(); std::string scheme; std::string authInfo; pObject->_request->getCredentials(scheme, authInfo); - obj->Set(JSLiteral("scheme"), JSString(scheme)); - obj->Set(JSLiteral("authInfo"), JSString(authInfo)); + obj->Set(js_method_context(),js_method_string("scheme"), js_method_string(scheme)); + obj->Set(js_method_context(),js_method_string("authInfo"), js_method_string(authInfo)); - return obj; + js_method_set_return_handle(obj); } JS_METHOD_IMPL(HttpRequestObject::setCredentials) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(2); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); std::string scheme = js_method_arg_as_std_string(0); std::string authInfo = js_method_arg_as_std_string(1); pObject->_request->setCredentials(scheme, authInfo); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::setVersion) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_request->setVersion(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getVersion) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSString(pObject->_request->getVersion()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_string(pObject->_request->getVersion()); } JS_METHOD_IMPL(HttpRequestObject::setContentLength) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_declare_uint32(contentLength, 0); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_declare_uint32(contentLength, 0); pObject->_request->setContentLength(contentLength); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getContentLength) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSUInt32(pObject->_request->getContentLength()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_handle(js_method_uint32(pObject->_request->getContentLength())); } JS_METHOD_IMPL(HttpRequestObject::setTransferEncoding) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_request->setTransferEncoding(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getTransferEncoding) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSString(pObject->_request->getTransferEncoding()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_string(pObject->_request->getTransferEncoding()); } JS_METHOD_IMPL(HttpRequestObject::setChunkedTransferEncoding) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_declare_bool(flag, 0); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_declare_bool(flag, 0); pObject->_request->setChunkedTransferEncoding(flag); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getChunkedTransferEncoding) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSBoolean(pObject->_request->getChunkedTransferEncoding()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_boolean(pObject->_request->getChunkedTransferEncoding()); } JS_METHOD_IMPL(HttpRequestObject::setContentType) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_assert_size_eq(1); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_request->setContentType(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getContentType) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSString(pObject->_request->getContentType()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_string(pObject->_request->getContentType()); } JS_METHOD_IMPL(HttpRequestObject::set) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_declare_string(name, 0); - js_method_arg_declare_string(value, 1); + js_method_declare_string(name, 0); + js_method_declare_string(value, 1); pObject->_request->add(name, value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::get) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_declare_string(name, 0); - js_method_arg_declare_string(defVal, 1); + js_method_declare_string(name, 0); + js_method_declare_string(defVal, 1); - return JSString(pObject->_request->get(name, defVal)); + js_method_set_return_string(pObject->_request->get(name, defVal)); } JS_METHOD_IMPL(HttpRequestObject::setKeepAlive) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - js_method_arg_declare_bool(flag, 0); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_declare_bool(flag, 0); pObject->_request->setKeepAlive(flag); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::getKeepAlive) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); - return JSBoolean(pObject->_request->getKeepAlive()); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + js_method_set_return_boolean(pObject->_request->getKeepAlive()); } JS_METHOD_IMPL(HttpRequestObject::reset) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); delete pObject->_request; pObject->_request = new HttpRequestObject::Request(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpRequestObject::dispose) { - HttpRequestObject* pObject = js_method_arg_unwrap_self(HttpRequestObject); - js_assert(pObject && pObject->_request, "HTTP Request has been disposed"); + HttpRequestObject* pObject = js_method_unwrap_self(HttpRequestObject); + js_method_assert(pObject && pObject->_request, "HTTP Request has been disposed"); delete pObject->_request; pObject->_request = 0; - return JSUndefined(); + js_method_set_return_undefined(); } diff --git a/src/js/modules/http/http_response.cpp b/src/js/modules/http/http_response.cpp index 3342df69ea..438b56c82f 100644 --- a/src/js/modules/http/http_response.cpp +++ b/src/js/modules/http/http_response.cpp @@ -67,166 +67,166 @@ HttpResponseObject::~HttpResponseObject() JS_CONSTRUCTOR_IMPL(HttpResponseObject) { HttpResponseObject* pObject = new HttpResponseObject(); - pObject->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pObject->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(HttpResponseObject::setStatus) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_declare_uint32(status, 0); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_declare_uint32(status, 0); pObject->_response->setStatus((Status)status); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getStatus) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSInt32(pObject->_response->getStatus()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_handle(js_method_int32(pObject->_response->getStatus())); } JS_METHOD_IMPL(HttpResponseObject::setReason) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_declare_string(reason, 0); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_declare_string(reason, 0); pObject->_response->setReason(reason); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getReason) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSString(pObject->_response->getReason()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_string(pObject->_response->getReason()); } JS_METHOD_IMPL(HttpResponseObject::setVersion) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_assert_size_eq(1); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_response->setVersion(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getVersion) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSString(pObject->_response->getVersion()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_string(pObject->_response->getVersion()); } JS_METHOD_IMPL(HttpResponseObject::setContentLength) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_declare_uint32(contentLength, 0); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_declare_uint32(contentLength, 0); pObject->_response->setContentLength(contentLength); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getContentLength) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSUInt32(pObject->_response->getContentLength()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_handle(js_method_uint32(pObject->_response->getContentLength())); } JS_METHOD_IMPL(HttpResponseObject::setTransferEncoding) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_assert_size_eq(1); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_response->setTransferEncoding(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getTransferEncoding) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSString(pObject->_response->getTransferEncoding()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_string(pObject->_response->getTransferEncoding()); } JS_METHOD_IMPL(HttpResponseObject::setChunkedTransferEncoding) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_declare_bool(flag, 0); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_declare_bool(flag, 0); pObject->_response->setChunkedTransferEncoding(flag); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getChunkedTransferEncoding) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSBoolean(pObject->_response->getChunkedTransferEncoding()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_boolean(pObject->_response->getChunkedTransferEncoding()); } JS_METHOD_IMPL(HttpResponseObject::setContentType) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_assert_size_eq(1); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string value = js_method_arg_as_std_string(0); pObject->_response->setContentType(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getContentType) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSString(pObject->_response->getContentType()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_string(pObject->_response->getContentType()); } JS_METHOD_IMPL(HttpResponseObject::setKeepAlive) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - js_method_arg_declare_bool(flag, 0); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_declare_bool(flag, 0); pObject->_response->setKeepAlive(flag); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::getKeepAlive) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); - return JSBoolean(pObject->_response->getKeepAlive()); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + js_method_set_return_boolean(pObject->_response->getKeepAlive()); } JS_METHOD_IMPL(getReasonForStatus) { - js_method_arg_declare_uint32(status, 0); - return JSString(HttpResponseObject::Response::getReasonForStatus((HttpResponseObject::Status)status)); + js_method_declare_uint32(status, 0); + js_method_set_return_string(HttpResponseObject::Response::getReasonForStatus((HttpResponseObject::Status)status)); } JS_METHOD_IMPL(HttpResponseObject::reset) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); delete pObject->_response; pObject->_response = new Response(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpResponseObject::dispose) { - HttpResponseObject* pObject = js_method_arg_unwrap_self(HttpResponseObject); - js_assert(pObject && pObject->_response, "HTTP Response has been disposed"); + HttpResponseObject* pObject = js_method_unwrap_self(HttpResponseObject); + js_method_assert(pObject && pObject->_response, "HTTP Response has been disposed"); delete pObject->_response; pObject->_response = 0; - return JSUndefined(); + js_method_set_return_undefined(); } JS_EXPORTS_INIT() diff --git a/src/js/modules/http/http_server.cpp b/src/js/modules/http/http_server.cpp index eb17d4ddf8..ea3880e6d9 100644 --- a/src/js/modules/http/http_server.cpp +++ b/src/js/modules/http/http_server.cpp @@ -72,15 +72,15 @@ JS_CLASS_INTERFACE(HttpServerObject, "HttpServer") JS_CONSTRUCTOR_IMPL(HttpServerObject) { bool useHttps = false; - if (js_method_arg_length() > 0) + if (js_method_args_length() > 0) { - js_method_arg_declare_bool(isSecure, 0); + js_method_declare_bool(isSecure, 0); useHttps = isSecure; } HttpServerObject* pServer = new HttpServerObject(useHttps); - pServer->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pServer->Wrap(js_method_self()); + js_method_set_return_self(); } HttpServerObject::HttpServerObject(bool secure) : @@ -100,7 +100,7 @@ HttpServerObject::~HttpServerObject() { if (!_requestHandler.IsEmpty()) { - _requestHandler.Dispose(); + _requestHandler.Reset(); } delete _pHttpServer; delete _pSocket; @@ -245,57 +245,58 @@ void HttpServerObject::handleRequest(HTTPServerRequest& request, HTTPServerRespo JS_METHOD_IMPL(HttpServerObject::_sendResponse) { - js_method_arg_declare_self(HttpServerObject, self); - js_method_arg_declare_uint32(responseId, 0); - js_method_arg_declare_object(response, 1); + js_method_declare_self(HttpServerObject, self); + js_method_declare_uint32(responseId, 0); + js_method_declare_object(response, 1); HTTPServerResponse* pResponse = self->findResponse(responseId); if (!pResponse) { - return JSBoolean(false); + js_method_set_return_false(); + return; } - JSLocalValueHandle status = response->Get(JSLiteral("status")); - JSLocalValueHandle reason = response->Get(JSLiteral("reason")); - JSLocalValueHandle contentType = response->Get(JSLiteral("contentType")); - JSLocalValueHandle contentLength = response->Get(JSLiteral("contentLength")); - JSLocalValueHandle transferEncoding = response->Get(JSLiteral("transferEncoding")); - JSLocalValueHandle chunkedTransferEncoding = response->Get(JSLiteral("chunkedTransferEncoding")); - JSLocalValueHandle keepAlive = response->Get(JSLiteral("keepAlive")); + JSMaybeLocalValueHandle status = response->Get(js_method_context(),js_method_string("status")); + JSMaybeLocalValueHandle reason = response->Get(js_method_context(),js_method_string("reason")); + JSMaybeLocalValueHandle contentType = response->Get(js_method_context(),js_method_string("contentType")); + JSMaybeLocalValueHandle contentLength = response->Get(js_method_context(),js_method_string("contentLength")); + JSMaybeLocalValueHandle transferEncoding = response->Get(js_method_context(),js_method_string("transferEncoding")); + JSMaybeLocalValueHandle chunkedTransferEncoding = response->Get(js_method_context(),js_method_string("chunkedTransferEncoding")); + JSMaybeLocalValueHandle keepAlive = response->Get(js_method_context(),js_method_string("keepAlive")); - if (!status.IsEmpty() && status->IsUint32()) + if (!status.IsEmpty() && status.ToLocalChecked()->IsUint32()) { - pResponse->setStatus((HTTPStatus)status->ToUint32()->Value()); + pResponse->setStatus((HTTPStatus)status.ToLocalChecked()->Uint32Value(js_method_context()).ToChecked()); } - if (!reason.IsEmpty() && reason->IsString()) + if (!reason.IsEmpty() && reason.ToLocalChecked()->IsString()) { - pResponse->setReason(js_handle_as_std_string(reason)); + pResponse->setReason(js_method_handle_as_std_string(reason.ToLocalChecked())); } - if (!contentType.IsEmpty() && contentType->IsString()) + if (!contentType.IsEmpty() && contentType.ToLocalChecked()->IsString()) { - pResponse->setContentType(js_handle_as_std_string(contentType)); + pResponse->setContentType(js_method_handle_as_std_string(contentType.ToLocalChecked())); } - if (!contentLength.IsEmpty() && contentLength->IsUint32()) + if (!contentLength.IsEmpty() && contentLength.ToLocalChecked()->IsUint32()) { - pResponse->setContentLength(contentLength->ToInt32()->Value()); + pResponse->setContentLength(contentLength.ToLocalChecked()->Int32Value(js_method_context()).ToChecked()); } - if (!transferEncoding.IsEmpty() && transferEncoding->IsString()) + if (!transferEncoding.IsEmpty() && transferEncoding.ToLocalChecked()->IsString()) { - pResponse->setTransferEncoding(js_handle_as_std_string(transferEncoding)); + pResponse->setTransferEncoding(js_method_handle_as_std_string(transferEncoding.ToLocalChecked())); } - if (!chunkedTransferEncoding.IsEmpty() && chunkedTransferEncoding->IsBoolean()) + if (!chunkedTransferEncoding.IsEmpty() && chunkedTransferEncoding.ToLocalChecked()->IsBoolean()) { - pResponse->setChunkedTransferEncoding(chunkedTransferEncoding->ToBoolean()->Value()); + pResponse->setChunkedTransferEncoding(chunkedTransferEncoding.ToLocalChecked()->ToBoolean(js_method_isolate())->Value()); } - if (!keepAlive.IsEmpty() && keepAlive->IsBoolean()) + if (!keepAlive.IsEmpty() && keepAlive.ToLocalChecked()->IsBoolean()) { - pResponse->setKeepAlive(keepAlive->ToBoolean()->Value()); + pResponse->setKeepAlive(keepAlive.ToLocalChecked()->ToBoolean(js_method_isolate())->Value()); } @@ -308,63 +309,63 @@ JS_METHOD_IMPL(HttpServerObject::_sendResponse) self->removeResponse(responseId); - return JSBoolean(ostrm->good()); + js_method_set_return_boolean(ostrm->good()); } JS_METHOD_IMPL(HttpServerObject::setMaxQueued) { - js_method_arg_declare_self(HttpServerObject, self); - js_method_arg_declare_uint32(value, 0); + js_method_declare_self(HttpServerObject, self); + js_method_declare_uint32(value, 0); self->_pParams->setMaxQueued(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpServerObject::setMaxThreads) { - js_method_arg_declare_self(HttpServerObject, self); - js_method_arg_declare_uint32(value, 0); + js_method_declare_self(HttpServerObject, self); + js_method_declare_uint32(value, 0); self->_pParams->setMaxThreads(value); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpServerObject::_setRpcId) { - js_method_arg_declare_self(HttpServerObject, self); - js_method_arg_declare_string(rpcId, 0); + js_method_declare_self(HttpServerObject, self); + js_method_declare_string(rpcId, 0); self->_rpcId = rpcId; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpServerObject::_read) { - js_method_arg_declare_self(HttpServerObject, self); - js_method_arg_declare_int32(streamId, 0); - js_method_arg_declare_external_object(BufferObject, buf, 1); - js_method_arg_declare_uint32(size, 2); - return JSUInt32(self->read(streamId, (char*)buf->buffer().data(), size)); + js_method_declare_self(HttpServerObject, self); + js_method_declare_int32(streamId, 0); + js_method_declare_external_object(BufferObject, buf, 1); + js_method_declare_uint32(size, 2); + js_method_set_return_handle(js_method_uint32(self->read(streamId, (char*)buf->buffer().data(), size))); } JS_METHOD_IMPL(HttpServerObject::_write) { - js_method_arg_declare_self(HttpServerObject, self); - js_method_arg_declare_int32(streamId, 0); - js_method_arg_declare_external_object(BufferObject, buf, 1); - js_method_arg_declare_uint32(size, 2); - return JSUInt32(self->write(streamId, (char*)buf->buffer().data(), size)); + js_method_declare_self(HttpServerObject, self); + js_method_declare_int32(streamId, 0); + js_method_declare_external_object(BufferObject, buf, 1); + js_method_declare_uint32(size, 2); + js_method_set_return_handle(js_method_uint32(self->write(streamId, (char*)buf->buffer().data(), size))); } JS_METHOD_IMPL(HttpServerObject::_listen) { - js_method_arg_declare_self(HttpServerObject, self); + js_method_declare_self(HttpServerObject, self); if (self->_pSocket) { - js_throw("HTTP Server already running"); + js_method_throw("HTTP Server already running"); } - js_method_arg_declare_string(ip, 0); - js_method_arg_declare_uint32(port, 1); - js_method_arg_declare_function(callback, 2); + js_method_declare_string(ip, 0); + js_method_declare_uint32(port, 1); + js_method_declare_function(callback, 2); try { @@ -400,12 +401,12 @@ JS_METHOD_IMPL(HttpServerObject::_listen) delete self->_pHttpServer; self->_pHttpServer = 0; JSArgumentVector jsonArg; - JSValueHandle error = JSString(e.displayText()); + JSValueHandle error = js_method_string(e.displayText()); jsonArg.push_back(error); js_function_call(callback, jsonArg.data(), jsonArg.size()); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_EXPORTS_INIT() diff --git a/src/js/modules/http/http_ssl_context.cpp b/src/js/modules/http/http_ssl_context.cpp index 980d40a868..472413f8ac 100644 --- a/src/js/modules/http/http_ssl_context.cpp +++ b/src/js/modules/http/http_ssl_context.cpp @@ -149,141 +149,141 @@ HttpSSLContextObject::~HttpSSLContextObject() JS_CONSTRUCTOR_IMPL(HttpSSLContextObject) { HttpSSLContextObject* pObject = new HttpSSLContextObject(); - pObject->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pObject->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(HttpSSLContextObject::setUsage) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_int32(usage, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_int32(usage, 0); self->_usage = (Context::Usage)usage; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getUsage) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSInt32(self->_usage); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_handle(js_method_int32(self->_usage)); } JS_METHOD_IMPL(HttpSSLContextObject::setPrivateKeyFile) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_string(privateKeyFile, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_string(privateKeyFile, 0); self->_privateKeyFile = privateKeyFile; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getPrivateKeyFile) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSString(self->_privateKeyFile); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_string(self->_privateKeyFile); } JS_METHOD_IMPL(HttpSSLContextObject::setCertificateKeyFile) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_string(certificateFile, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_string(certificateFile, 0); self->_certificateFile = certificateFile; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getCertificateKeyFile) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSString(self->_certificateFile); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_string(self->_certificateFile); } JS_METHOD_IMPL(HttpSSLContextObject::setCaLocation) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_string(caLocation, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_string(caLocation, 0); self->_caLocation = caLocation; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getCaLocation) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSString(self->_caLocation); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_string(self->_caLocation); } JS_METHOD_IMPL(HttpSSLContextObject::setCipherList) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_string(cipherList, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_string(cipherList, 0); self->_cipherList = cipherList; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getCipherList) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSString(self->_cipherList); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_string(self->_cipherList); } JS_METHOD_IMPL(HttpSSLContextObject::setVerificationMode) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_int32(verificationMode, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_int32(verificationMode, 0); self->_verificationMode = (Context::VerificationMode)verificationMode; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getVerificationMode) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSInt32(self->_verificationMode); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_handle(js_method_int32(self->_verificationMode)); } JS_METHOD_IMPL(HttpSSLContextObject::setVerificationDepth) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_int32(verificationDepth, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_int32(verificationDepth, 0); self->_verificationDepth = verificationDepth; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getVerificationDepth) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSInt32(self->_verificationDepth); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_handle(js_method_int32(self->_verificationDepth)); } JS_METHOD_IMPL(HttpSSLContextObject::setLoadDefaultCa) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_bool(loadDefaultCa, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_bool(loadDefaultCa, 0); self->_loadDefaultCAs = loadDefaultCa; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::getLoadDefaultCa) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - return JSBoolean(self->_loadDefaultCAs); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_set_return_boolean(self->_loadDefaultCAs); } JS_METHOD_IMPL(HttpSSLContextObject::setInvalidCertificateHandlerId) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_string(invalidCertHandlerId, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_string(invalidCertHandlerId, 0); self->_invalidCertHandlerId = invalidCertHandlerId; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::setPassphraseHandlerId) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); - js_method_arg_declare_string(passPhraseHandlerId, 0); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); + js_method_declare_string(passPhraseHandlerId, 0); self->_passPhraseHandlerId = passPhraseHandlerId; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(HttpSSLContextObject::registerContext) { - HttpSSLContextObject* self = js_method_arg_unwrap_self(HttpSSLContextObject); + HttpSSLContextObject* self = js_method_unwrap_self(HttpSSLContextObject); if (self->_pContext) { - js_throw("Context Already Registered"); + js_method_throw("Context Already Registered"); } try @@ -311,9 +311,9 @@ JS_METHOD_IMPL(HttpSSLContextObject::registerContext) } catch(const Poco::Exception& e) { - js_throw(e.message().c_str()); + js_method_throw(e.message().c_str()); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_EXPORTS_INIT() diff --git a/src/js/modules/inotify/inotify.cpp b/src/js/modules/inotify/inotify.cpp index 5d5142f7a5..6918951da1 100644 --- a/src/js/modules/inotify/inotify.cpp +++ b/src/js/modules/inotify/inotify.cpp @@ -27,12 +27,12 @@ JS_METHOD_IMPL(__inotify_init) { - return JSInt32(inotify_init()); + return js_method_int32(inotify_init()); } JS_METHOD_IMPL(__inotify_add_watch) { - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_int32(0); js_method_arg_assert_string(1); js_method_arg_assert_uint32(2); @@ -41,12 +41,12 @@ JS_METHOD_IMPL(__inotify_add_watch) std::string pathname = js_method_arg_as_std_string(1); uint32_t mask = js_method_arg_as_uint32(2); - return JSInt32(inotify_add_watch(fd, pathname.c_str(), mask)); + return js_method_int32(inotify_add_watch(fd, pathname.c_str(), mask)); } JS_METHOD_IMPL(__inotify_rm_watch) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_int32(0); js_method_arg_assert_int32(1); @@ -54,12 +54,12 @@ JS_METHOD_IMPL(__inotify_rm_watch) int32_t fd = js_method_arg_as_int32(0); int32_t wd = js_method_arg_as_int32(0); - return JSInt32(inotify_rm_watch(fd, wd)); + return js_method_int32(inotify_rm_watch(fd, wd)); } JS_METHOD_IMPL(__inotify_get_events) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int32_t fd = js_method_arg_as_int32(0); char buf[BUF_LEN] __attribute__ ((aligned(8))); diff --git a/src/js/modules/isolate/isolate.cpp b/src/js/modules/isolate/isolate.cpp index 71186b1324..372f64dab1 100644 --- a/src/js/modules/isolate/isolate.cpp +++ b/src/js/modules/isolate/isolate.cpp @@ -56,99 +56,100 @@ IsolateObject::~IsolateObject() JS_CONSTRUCTOR_IMPL(IsolateObject) { IsolateObject* pObject = new IsolateObject(pthread_self()); - pObject->Wrap(js_method_arg_self()); - return js_method_arg_self(); + pObject->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(IsolateObject::run) { - js_enter_scope(); - js_method_arg_declare_self(IsolateObject, pSelf); - js_method_arg_declare_string(path, 0); + js_method_enter_scope(); + js_method_declare_self(IsolateObject, pSelf); + js_method_declare_string(path, 0); boost::filesystem::path script(path.c_str()); JSIsolateManager::instance().run(pSelf->_pIsolate, script); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(IsolateObject::runSource) { - js_enter_scope(); - js_method_arg_declare_self(IsolateObject, pSelf); - js_method_arg_declare_string(source, 0); + js_method_enter_scope(); + js_method_declare_self(IsolateObject, pSelf); + js_method_declare_string(source, 0); JSIsolateManager::instance().runSource(pSelf->_pIsolate, source); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(IsolateObject::stop) { - js_method_arg_declare_self(IsolateObject, pSelf); + js_method_declare_self(IsolateObject, pSelf); pSelf->_pIsolate->terminate(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(IsolateObject::join) { - js_method_arg_declare_self(IsolateObject, pSelf); + js_method_declare_self(IsolateObject, pSelf); pSelf->_pIsolate->join(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(setChildInterIsolateHandler) { - js_method_arg_declare_persistent_function(func, 0); - js_method_arg_declare_uint32(eventEmitterFd, 1); + js_method_declare_copyable_persistent_function(func, 0); + js_method_declare_uint32(eventEmitterFd, 1); OSS::JS::JSIsolateManager::instance().getIsolate()->setEventEmitterFd(eventEmitterFd); OSS::JS::JSIsolateManager::instance().getIsolate()->eventLoop()->interIsolate().setHandler(func); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(setRootInterIsolateHandler) { - js_method_arg_declare_persistent_function(func, 0); - js_method_arg_declare_uint32(eventEmitterFd, 1); + js_method_declare_copyable_persistent_function(func, 0); + js_method_declare_uint32(eventEmitterFd, 1); OSS::JS::JSIsolateManager::instance().rootIsolate()->setEventEmitterFd(eventEmitterFd); OSS::JS::JSIsolateManager::instance().rootIsolate()->eventLoop()->interIsolate().setHandler(func); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(IsolateObject::execute) { - js_enter_scope(); - js_method_arg_declare_self(IsolateObject, pSelf); - js_method_arg_declare_string(request, 0); - js_method_arg_declare_uint32(timeout, 1); + js_method_enter_scope(); + js_method_declare_self(IsolateObject, pSelf); + js_method_declare_string(request, 0); + js_method_declare_uint32(timeout, 1); std::string result; if (!pSelf->_pIsolate->eventLoop()->interIsolate().execute(request, result, timeout, 0)) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return JSString(result); + js_method_set_return_string(result); } JS_METHOD_IMPL(IsolateObject::notify) { - js_enter_scope(); - js_method_arg_declare_self(IsolateObject, pSelf); - js_method_arg_declare_string(request, 0); + js_method_enter_scope(); + js_method_declare_self(IsolateObject, pSelf); + js_method_declare_string(request, 0); pSelf->_pIsolate->eventLoop()->interIsolate().notify(request, 0); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(notifyParentIsolate) { - js_enter_scope(); - js_method_arg_declare_string(request, 0); + js_method_enter_scope(); + js_method_declare_string(request, 0); OSS::JS::JSIsolate::Ptr pIsolate = OSS::JS::JSIsolateManager::instance().getIsolate(); if (pIsolate && !pIsolate->isRoot()) { pIsolate->getParentIsolate()->notify(request, 0); } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(isRootIsolate) { - return JSBoolean(OSS::JS::JSIsolateManager::instance().rootIsolate()->isThreadSelf()); + js_method_set_return_boolean(OSS::JS::JSIsolateManager::instance().rootIsolate()->isThreadSelf()); } JS_EXPORTS_INIT() diff --git a/src/js/modules/logger/logger.cpp b/src/js/modules/logger/logger.cpp index 9cc77df4bb..917a3a9771 100644 --- a/src/js/modules/logger/logger.cpp +++ b/src/js/modules/logger/logger.cpp @@ -22,98 +22,103 @@ #include "OSS/UTL/CoreUtils.h" -static v8::Handle __log(const v8::Arguments& args) +JS_METHOD_IMPL(__log) { - if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsString()) + if (_args_.Length() < 2 || !_args_[0]->IsInt32() || !_args_[1]->IsString()) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; - v8::String::Utf8Value arg1(args[1]); - OSS::log(*arg1, (OSS::LogPriority)args[0]->ToInt32()->Value()); - return v8::Undefined(); + js_method_enter_scope(); + + std::string arg1 = *v8::String::Utf8Value(js_method_isolate(),_args_[1]); + + OSS::log(arg1, (OSS::LogPriority)_args_[0]->Int32Value(js_method_context()).ToChecked()); + + js_method_set_return_undefined(); } -static v8::Handle __log_init(const v8::Arguments& args) +JS_METHOD_IMPL(__log_init) { - if (args.Length() < 1 && !args[0]->IsString()) + if (_args_.Length() < 1 && !_args_[0]->IsString()) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - std::string path; OSS::LogPriority logLevel = OSS::PRIO_INFORMATION; std::string format = "%h-%M-%S.%i: %t"; bool compress = true; int purgeCount = 7; - v8::HandleScope scope; + js_method_enter_scope(); - path = *v8::String::Utf8Value(args[0]); - if (args.Length() >= 2 && args[1]->IsInt32()) + std::string path = *v8::String::Utf8Value(js_method_isolate(),_args_[0]); + if (_args_.Length() >= 2 && _args_[1]->IsInt32()) { - logLevel = (OSS::LogPriority)args[1]->Int32Value(); + logLevel = (OSS::LogPriority)_args_[1]->Int32Value(js_method_context()).ToChecked(); } - if (args.Length() >= 3 && args[2]->IsString()) + if (_args_.Length() >= 3 && _args_[2]->IsString()) { - format = *v8::String::Utf8Value(args[2]); + format = *v8::String::Utf8Value(js_method_isolate(),_args_[2]); } - if (args.Length() >= 4 && args[3]->IsBoolean()) + if (_args_.Length() >= 4 && _args_[3]->IsBoolean()) { - compress = args[3]->BooleanValue(); + compress = _args_[3]->BooleanValue(js_method_isolate()); } - if (args.Length() >= 5 && args[4]->IsInt32()) + if (_args_.Length() >= 5 && _args_[4]->IsInt32()) { - purgeCount = args[4]->Int32Value(); + purgeCount = _args_[4]->Int32Value(js_method_context()).ToChecked(); } OSS::logger_init(path, logLevel, format, compress ? "true" : "false", OSS::string_from_number(purgeCount)); - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle __log_level_get(v8::Local property, const v8::AccessorInfo& info) +JS_ACCESSOR_GETTER_IMPL(__log_level_get) { - return v8::Integer::New(OSS::log_get_level()); + js_method_set_return_integer(OSS::log_get_level()); } -void __log_level_set(v8::Local property, v8::Local value, const v8::AccessorInfo& info) +JS_ACCESSOR_SETTER_IMPL(__log_level_set) { - OSS::log_reset_level((OSS::LogPriority)value->Int32Value()); + OSS::log_reset_level((OSS::LogPriority)value->Int32Value(js_method_context()).ToChecked()); } -static v8::Handle init_exports(const v8::Arguments& args) +JS_EXPORTS_INIT() { - v8::HandleScope scope; - v8::Persistent exports = v8::Persistent::New(v8::Object::New()); // // Methods // - exports->Set(v8::String::New("log"), v8::FunctionTemplate::New(__log)->GetFunction()); - exports->Set(v8::String::New("init"), v8::FunctionTemplate::New(__log_init)->GetFunction()); - + + js_export_method("log", __log ); + js_export_method("init", __log_init ); + + // // Mutable Properties // - exports->SetAccessor(v8::String::New("level"), __log_level_get, __log_level_set); + + js_export_accessor("level", __log_level_get, __log_level_set); // // Constants // - exports->Set(v8::String::New("NOTICE"), v8::Int32::New(OSS::PRIO_NOTICE), v8::ReadOnly); - exports->Set(v8::String::New("INFO"), v8::Int32::New(OSS::PRIO_INFORMATION), v8::ReadOnly); - exports->Set(v8::String::New("DEBUG"), v8::Int32::New(OSS::PRIO_DEBUG), v8::ReadOnly); - exports->Set(v8::String::New("TRACE"), v8::Int32::New(OSS::PRIO_TRACE), v8::ReadOnly); - exports->Set(v8::String::New("WARNING"), v8::Int32::New(OSS::PRIO_WARNING), v8::ReadOnly); - exports->Set(v8::String::New("ERROR"), v8::Int32::New(OSS::PRIO_ERROR), v8::ReadOnly); - exports->Set(v8::String::New("CRITICAL"), v8::Int32::New(OSS::PRIO_CRITICAL), v8::ReadOnly); - exports->Set(v8::String::New("FATAL"), v8::Int32::New(OSS::PRIO_FATAL), v8::ReadOnly); + js_export_int32("NOTICE",OSS::PRIO_NOTICE); + js_export_int32("INFO",OSS::PRIO_INFORMATION); + js_export_int32("DEBUG",OSS::PRIO_DEBUG); + js_export_int32("TRACE",OSS::PRIO_TRACE); + js_export_int32("WARNING",OSS::PRIO_WARNING); + js_export_int32("ERROR",OSS::PRIO_ERROR); + js_export_int32("CRITICAL",OSS::PRIO_CRITICAL); + js_export_int32("FATAL",OSS::PRIO_FATAL); - return exports; + js_export_finalize(); } JS_REGISTER_MODULE(Logger); diff --git a/src/js/modules/pinger/pinger.cpp b/src/js/modules/pinger/pinger.cpp index d6adc45916..3f8f4c7a6a 100644 --- a/src/js/modules/pinger/pinger.cpp +++ b/src/js/modules/pinger/pinger.cpp @@ -25,7 +25,7 @@ struct ping_host_data_t { OSS::JS::JSIsolate::Ptr isolate; - JSPersistentFunctionHandle* cb; + JSCopyablePersistentFunctionHandle* cb; std::string host; bool timeout; int sequence; @@ -38,20 +38,26 @@ static void ping_host_callback_isolated(void* user_data) { ping_host_data_t* data = static_cast(user_data); assert(data); + + v8::Isolate* isolate = data->isolate->getV8Isolate(); + v8::Local context = isolate->GetCurrentContext(); + v8::Local global = context->Global(); - JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("host"), JSString(data->host.c_str())); - result->ToObject()->Set(JSLiteral("timeout"), JSBoolean(data->timeout)); - result->ToObject()->Set(JSLiteral("sequence"), JSInt32(data->sequence)); - result->ToObject()->Set(JSLiteral("bytes"), JSInt32(data->bytes)); - result->ToObject()->Set(JSLiteral("ttl"), JSInt32(data->ttl)); - result->ToObject()->Set(JSLiteral("roundtrip"), JSInt32(data->roundtrip)); + JSLocalValueHandle result = JSObject(isolate); + result->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"host"), JSString(isolate,data->host.c_str())); + result->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"timeout"), JSBoolean(isolate,data->timeout)); + result->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"sequence"), JSInt32(isolate,data->sequence)); + result->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"bytes"), JSInt32(isolate,data->bytes)); + result->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"ttl"), JSInt32(isolate,data->ttl)); + result->ToObject(context).ToLocalChecked()->Set(context, JSString(isolate,"roundtrip"), JSInt32(isolate,data->roundtrip)); JSLocalArgumentVector args; args.push_back(result); + + JSFunctionHandle callback = data->cb->Get(isolate); - (*data->cb)->Call(js_get_global(), args.size(), args.data()); - data->cb->Dispose(); + callback->Call(context, global, args.size(), args.data()); + data->cb->Reset(); delete data->cb; delete data; } @@ -75,7 +81,7 @@ static void ping_host_callback(const std::string& host, bool timeout, int sequen JS_METHOD_IMPL(__ping_host) { - js_method_arg_assert_size_eq(4); + js_method_args_assert_size_eq(4); js_method_arg_assert_string(0); js_method_arg_assert_uint32(1); js_method_arg_assert_uint32(2); @@ -86,11 +92,11 @@ JS_METHOD_IMPL(__ping_host) ping_host_data_t* data = new ping_host_data_t(); - data->cb = new JSPersistentFunctionHandle; + data->cb = new JSCopyablePersistentFunctionHandle; data->isolate = OSS::JS::JSIsolate::getIsolate(); *data->cb = js_method_arg_as_persistent_function(3); - return JSBoolean(OSS::Net::Pinger::ping_host(host, sequence, ttl, boost::bind(ping_host_callback, _1, _2, _3, _4, _5, _6, _7), (void*)data)); + js_method_set_return_boolean(OSS::Net::Pinger::ping_host(host, sequence, ttl, boost::bind(ping_host_callback, _1, _2, _3, _4, _5, _6, _7), (void*)data)); } JS_EXPORTS_INIT() diff --git a/src/js/modules/pipe/pipe.cpp b/src/js/modules/pipe/pipe.cpp index 0086a6de53..621bcb6da8 100644 --- a/src/js/modules/pipe/pipe.cpp +++ b/src/js/modules/pipe/pipe.cpp @@ -23,12 +23,12 @@ #include #include -static v8::Handle __pipe(const v8::Arguments& args) +JS_METHOD_IMPL(__pipe) { int flags = 0; - if (args.Length() >= 1 && args[0]->IsInt32()) + if (_args_.Length() >= 1 && _args_[0]->IsInt32()) { - flags = args[0]->ToInt32()->Value(); + flags = _args_[0]->Int32Value(js_method_context()).ToChecked(); } int ret = 0; int pipefd[2]; @@ -44,21 +44,19 @@ static v8::Handle __pipe(const v8::Arguments& args) #endif if (ret == 0) { - v8::Handle result = v8::Array::New(2); - result->Set(0, v8::Int32::New(pipefd[0])); - result->Set(1, v8::Int32::New(pipefd[1])); - return result; + JSArrayHandle result = js_method_array(2); + result->Set(js_method_context(), 0, js_method_int32(pipefd[0])); + result->Set(js_method_context(), 1, js_method_int32(pipefd[1])); + js_method_set_return_handle(result); } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle init_exports(const v8::Arguments& args) +JS_EXPORTS_INIT() { - v8::HandleScope scope; - v8::Persistent exports = v8::Persistent::New(v8::Object::New()); - exports->Set(v8::String::New("pipe"), v8::FunctionTemplate::New(__pipe)->GetFunction()); - return exports; + js_export_method("pipe", __pipe ); + js_export_finalize(); } JS_REGISTER_MODULE(Pipe); diff --git a/src/js/modules/poll/poll.cpp b/src/js/modules/poll/poll.cpp index bec6d6640d..199fa77d6e 100644 --- a/src/js/modules/poll/poll.cpp +++ b/src/js/modules/poll/poll.cpp @@ -24,14 +24,18 @@ typedef std::vector PollFD; -static void array_to_pollfd_vector(v8::Handle& input, PollFD& output) +static void array_to_pollfd_vector(v8::Isolate* isolate, v8::Handle& input, PollFD& output) { - v8::HandleScope scope; + v8::Local context = isolate->GetCurrentContext(); + for(uint32_t i = 0; i < input->Length(); i++) { - v8::Handle item = input->Get(i)->ToObject(); - v8::Handle fd = item->Get(v8::String::New("fd"))->ToInteger(); - v8::Handle events = item->Get(v8::String::New("events"))->ToInteger(); + v8::Handle item = + input->Get(context,i).ToLocalChecked()->ToObject(context).ToLocalChecked(); + v8::Handle fd = + item->Get(context,JSString(isolate,"fd")).ToLocalChecked()->ToInteger(context).ToLocalChecked(); + v8::Handle events = + item->Get(context,JSString(isolate,"events")).ToLocalChecked()->ToInteger(context).ToLocalChecked(); pollfd pfd; pfd.fd = fd->Value(); @@ -41,66 +45,69 @@ static void array_to_pollfd_vector(v8::Handle& input, PollFD& output) } } -static void pollfd_vector_to_array(PollFD& input, v8::Handle& output) +static void pollfd_vector_to_array(v8::Isolate* isolate, PollFD& input, v8::Handle& output) { + v8::Local context = isolate->GetCurrentContext(); + uint32_t index = 0; for (PollFD::iterator iter = input.begin(); iter != input.end(); iter++) { - v8::Handle item = v8::Object::New(); - v8::Handle fd = v8::Integer::New(iter->fd); - v8::Handle events = v8::Integer::New(iter->events); - v8::Handle revents = v8::Integer::New(iter->revents); + v8::Handle item = JSObject(isolate); + v8::Handle fd = JSInteger(isolate,iter->fd); + v8::Handle events = JSInteger(isolate,iter->events); + v8::Handle revents = JSInteger(isolate,iter->revents); - item->Set(v8::String::New("fd"), fd); - item->Set(v8::String::New("events"), events); - item->Set(v8::String::New("revents"), revents); + item->Set(context, JSString(isolate,"fd"), fd); + item->Set(context, JSString(isolate,"events"), events); + item->Set(context, JSString(isolate,"revents"), revents); - output->Set(index++, item); + output->Set(context, index++, item); } } -static v8::Handle __poll(const v8::Arguments& args) +JS_METHOD_IMPL(__poll) { - if (args.Length() < 1 || !args[0]->IsArray()) + if (_args_.Length() < 1 || !_args_[0]->IsArray()) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - v8::HandleScope scope; + js_method_enter_scope(); PollFD pfds; - v8::Handle args0 = v8::Handle::Cast(args[0]); + v8::Handle args0 = v8::Handle::Cast(_args_[0]); int timeout = -1; - array_to_pollfd_vector(args0, pfds); + array_to_pollfd_vector(js_method_isolate(), args0, pfds); - if (args.Length() >= 2 && args[1]->IsNumber()) + if (_args_.Length() >= 2 && _args_[1]->IsNumber()) { - timeout = args[1]->IntegerValue(); + timeout = _args_[1]->IntegerValue(js_method_context()).ToChecked(); } - v8::Handle result = v8::Array::New(2); + v8::Handle result = js_method_array(2); int ret = ::poll(pfds.data(), pfds.size(), timeout); - result->Set(0, v8::Integer::New(ret)); + result->Set(js_method_context(), 0, js_method_integer(ret)); if (ret == 0 || ret == -1) { - return result; + js_method_set_return_handle(result); + return; } - v8::Handle pfdsout = v8::Array::New(pfds.size()); - pollfd_vector_to_array(pfds, pfdsout); - result->Set(1, pfdsout); - return result; + v8::Handle pfdsout = js_method_array(pfds.size()); + pollfd_vector_to_array(js_method_isolate(), pfds, pfdsout); + result->Set(js_method_context(), 1, pfdsout); + js_method_set_return_handle(result); } -static v8::Handle init_exports(const v8::Arguments& args) +JS_EXPORTS_INIT() { - v8::HandleScope scope; - v8::Persistent exports = v8::Persistent::New(v8::Object::New()); - // // Methods // - exports->Set(v8::String::New("poll"), v8::FunctionTemplate::New(__poll)->GetFunction()); + + js_export_method("poll", __poll ); + // // Mutable Properties // @@ -108,28 +115,28 @@ static v8::Handle init_exports(const v8::Arguments& args) // // Constants // - CONST_EXPORT(POLLIN); /* There is data to read. */ - CONST_EXPORT(POLLPRI); /* There is urgent data to read. */ - CONST_EXPORT(POLLOUT); /* Writing now will not block. */ + js_export_const(POLLIN); /* There is data to read. */ + js_export_const(POLLPRI); /* There is urgent data to read. */ + js_export_const(POLLOUT); /* Writing now will not block. */ #if defined __USE_XOPEN || defined __USE_XOPEN2K8 - CONST_EXPORT(POLLRDNORM); /* Normal data may be read. */ - CONST_EXPORT(POLLRDBAND); /* Priority data may be read. */ - CONST_EXPORT(POLLWRNORM); /* Writing now will not block. */ - CONST_EXPORT(POLLWRBAND); /* Priority data may be written. */ + js_export_const(POLLRDNORM); /* Normal data may be read. */ + js_export_const(POLLRDBAND); /* Priority data may be read. */ + js_export_const(POLLWRNORM); /* Writing now will not block. */ + js_export_const(POLLWRBAND); /* Priority data may be written. */ #endif #ifdef __USE_GNU - CONST_EXPORT(POLLMSG); - CONST_EXPORT(POLLREMOVE); - CONST_EXPORT(POLLRDHUP); + js_export_const(POLLMSG); + js_export_const(POLLREMOVE); + js_export_const(POLLRDHUP); #endif - CONST_EXPORT(POLLERR); /* Error condition. */ - CONST_EXPORT(POLLHUP); /* Hung up. */ - CONST_EXPORT(POLLNVAL); /* Invalid polling request. */ + js_export_const(POLLERR); /* Error condition. */ + js_export_const(POLLHUP); /* Hung up. */ + js_export_const(POLLNVAL); /* Invalid polling request. */ - return exports; + js_export_finalize(); } JS_REGISTER_MODULE(Poll); diff --git a/src/js/modules/process/process.cpp b/src/js/modules/process/process.cpp index d98a1cabf0..15dfc762eb 100644 --- a/src/js/modules/process/process.cpp +++ b/src/js/modules/process/process.cpp @@ -31,7 +31,7 @@ JS_CONSTRUCTOR_IMPL(ProcessObject) { ProcessObject* pProcess = 0; - js_method_arg_assert_size_gteq(2); + js_method_args_assert_size_gteq(2); js_method_arg_assert_string(0); js_method_arg_assert_string(1); @@ -40,13 +40,13 @@ JS_CONSTRUCTOR_IMPL(ProcessObject) std::string shutdownCommand; std::string pidFile; - if (js_method_arg_length() >= 3) + if (js_method_args_length() >= 3) { js_method_arg_assert_string(2); startupCommand = js_method_arg_as_std_string(2); } - if (js_method_arg_length() >= 4) + if (js_method_args_length() >= 4) { js_method_arg_assert_string(3); pidFile = js_method_arg_as_std_string(3); @@ -55,58 +55,58 @@ JS_CONSTRUCTOR_IMPL(ProcessObject) pProcess = new ProcessObject(); pProcess->_pProcess = new ProcessObject::Process(processName, startupCommand, shutdownCommand, pidFile); pProcess->_pProcess->setDeadProcAction(ProcessObject::Process::ProcessUnmonitor); - pProcess->Wrap(js_method_arg_self()); + pProcess->Wrap(js_method_self()); - return js_method_arg_self(); + js_method_set_return_self(); } JS_METHOD_IMPL(ProcessObject::run) { - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); - return JSBoolean(pProcess->_pProcess->executeAndMonitor()); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); + js_method_set_return_boolean(pProcess->_pProcess->executeAndMonitor()); } JS_METHOD_IMPL(ProcessObject::kill) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int signal = js_method_arg_as_int32(0); - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); - return JSInt32(pProcess->_pProcess->kill(signal)); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); + js_method_set_return_handle(js_method_int32(pProcess->_pProcess->kill(signal))); } JS_METHOD_IMPL(ProcessObject::stop) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int signal = js_method_arg_as_int32(0); - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); - return JSBoolean(pProcess->_pProcess->shutDown(signal)); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); + js_method_set_return_boolean(pProcess->_pProcess->shutDown(signal)); } JS_METHOD_IMPL(ProcessObject::restart) { - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); - return JSBoolean(pProcess->_pProcess->restart()); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); + js_method_set_return_boolean(pProcess->_pProcess->restart()); } JS_METHOD_IMPL(ProcessObject::unmonitor) { - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); pProcess->_pProcess->unmonitor(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ProcessObject::isAlive) { - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); - return JSBoolean(pProcess->_pProcess->isAlive()); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); + js_method_set_return_boolean(pProcess->_pProcess->isAlive()); } JS_METHOD_IMPL(ProcessObject::getPid) { - ProcessObject* pProcess = js_method_arg_unwrap_self(ProcessObject); - return JSInt32(pProcess->_pProcess->getPID()); + ProcessObject* pProcess = js_method_unwrap_self(ProcessObject); + js_method_set_return_handle(js_method_int32(pProcess->_pProcess->getPID())); } JS_EXPORTS_INIT() diff --git a/src/js/modules/resip_ua/ResipClientRegistrationHandler.cpp b/src/js/modules/resip_ua/ResipClientRegistrationHandler.cpp index 3bea2ca73e..7a19986679 100644 --- a/src/js/modules/resip_ua/ResipClientRegistrationHandler.cpp +++ b/src/js/modules/resip_ua/ResipClientRegistrationHandler.cpp @@ -93,8 +93,8 @@ JS_CONSTRUCTOR_IMPL(ResipClientRegistrationHandler) ResipClientRegistrationHandler* object = new ResipClientRegistrationHandler(); object->_handler = new client_registration_handler(object); object->_isolate = OSS::JS::JSIsolate::getIsolate(); - object->Wrap(js_method_arg_self()); - return js_method_arg_self(); + object->Wrap(js_method_self()); + return js_method_self(); } ResipClientRegistrationHandler::ResipClientRegistrationHandler() : @@ -141,47 +141,47 @@ ResipClientRegistrationHandler::~ResipClientRegistrationHandler() JS_METHOD_IMPL(ResipClientRegistrationHandler::handleOnSuccess) { - js_method_arg_declare_self(ResipClientRegistrationHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientRegistrationHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnSuccess = new JSPersistentFunctionHandle; *(self->_handleOnSuccess) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientRegistrationHandler::handleOnRemoved) { - js_method_arg_declare_self(ResipClientRegistrationHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientRegistrationHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnRemoved = new JSPersistentFunctionHandle; *(self->_handleOnRemoved) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientRegistrationHandler::handleOnRequestRetry) { - js_method_arg_declare_self(ResipClientRegistrationHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientRegistrationHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnRequestRetry = new JSPersistentFunctionHandle; *(self->_handleOnRequestRetry) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientRegistrationHandler::handleOnFailure) { - js_method_arg_declare_self(ResipClientRegistrationHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientRegistrationHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnFailure = new JSPersistentFunctionHandle; *(self->_handleOnFailure) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientRegistrationHandler::handleOnRefreshRequired) { - js_method_arg_declare_self(ResipClientRegistrationHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientRegistrationHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnRefreshRequired = new JSPersistentFunctionHandle; *(self->_handleOnRefreshRequired) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } void ResipClientRegistrationHandler::onSuccessIsolated(void* user_data) @@ -191,10 +191,10 @@ void ResipClientRegistrationHandler::onSuccessIsolated(void* user_data) if (_handleOnSuccess) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnSuccess)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnSuccess)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -206,10 +206,10 @@ void ResipClientRegistrationHandler::onRemovedIsolated(void* user_data) if (_handleOnRemoved) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnRemoved)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnRemoved)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -221,10 +221,10 @@ void ResipClientRegistrationHandler::onRequestRetryIsolated(void* user_data) if (_handleOnRequestRetry) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnRequestRetry)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnRequestRetry)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -236,10 +236,10 @@ void ResipClientRegistrationHandler::onFailureIsolated(void* user_data) if (_handleOnFailure) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnFailure)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnFailure)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -251,10 +251,10 @@ void ResipClientRegistrationHandler::onRefreshRequiredIsolated(void* user_data) if (_handleOnRefreshRequired) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnRefreshRequired)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnRefreshRequired)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } diff --git a/src/js/modules/resip_ua/ResipClientSubscriptionHandler.cpp b/src/js/modules/resip_ua/ResipClientSubscriptionHandler.cpp index 20d3b1440b..075f8b665c 100644 --- a/src/js/modules/resip_ua/ResipClientSubscriptionHandler.cpp +++ b/src/js/modules/resip_ua/ResipClientSubscriptionHandler.cpp @@ -116,8 +116,8 @@ JS_CONSTRUCTOR_IMPL(ResipClientSubscriptionHandler) ResipClientSubscriptionHandler* object = new ResipClientSubscriptionHandler(); object->_handler = new client_subscription_handler(object); object->_isolate = OSS::JS::JSIsolate::getIsolate(); - object->Wrap(js_method_arg_self()); - return js_method_arg_self(); + object->Wrap(js_method_self()); + return js_method_self(); } ResipClientSubscriptionHandler::ResipClientSubscriptionHandler() : @@ -182,65 +182,65 @@ ResipClientSubscriptionHandler::~ResipClientSubscriptionHandler() JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnUpdatePending) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnUpdatePending = new JSPersistentFunctionHandle; *(self->_handleOnUpdatePending) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnUpdateActive) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnUpdateActive = new JSPersistentFunctionHandle; *(self->_handleOnUpdateActive) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnUpdateExtension) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnUpdateExtension = new JSPersistentFunctionHandle; *(self->_handleOnUpdateExtension) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnTerminated) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnTerminated = new JSPersistentFunctionHandle; *(self->_handleOnTerminated) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnNewSubscription) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnNewSubscription = new JSPersistentFunctionHandle; *(self->_handleOnNewSubscription) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnNotifyNotReceived) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnNotifyNotReceived = new JSPersistentFunctionHandle; *(self->_handleOnNotifyNotReceived) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipClientSubscriptionHandler::handleOnFlowTerminated) { - js_method_arg_declare_self(ResipClientSubscriptionHandler, self); - js_method_arg_declare_persistent_function(handler, 0); + js_method_declare_self(ResipClientSubscriptionHandler, self); + js_method_declare_persistent_function(handler, 0); self->_handleOnFlowTerminated = new JSPersistentFunctionHandle; *(self->_handleOnFlowTerminated) = handler; - return JSUndefined(); + js_method_set_return_undefined(); } void ResipClientSubscriptionHandler::onUpdatePendingIsolated(void* user_data) @@ -250,13 +250,13 @@ void ResipClientSubscriptionHandler::onUpdatePendingIsolated(void* user_data) if (_handleOnUpdatePending) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); - result->ToObject()->Set(JSLiteral("eventBody"), JSString(data->eventBody.c_str())); - result->ToObject()->Set(JSLiteral("isOutOfOrder"), JSBoolean(data->isOutOfOrder)); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("eventBody"), JSString(data->eventBody.c_str())); + result->ToObject()->Set(JSString("isOutOfOrder"), JSBoolean(data->isOutOfOrder)); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnUpdatePending)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnUpdatePending)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -268,13 +268,13 @@ void ResipClientSubscriptionHandler::onUpdateActiveIsolated(void* user_data) if (_handleOnUpdateActive) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); - result->ToObject()->Set(JSLiteral("eventBody"), JSString(data->eventBody.c_str())); - result->ToObject()->Set(JSLiteral("isOutOfOrder"), JSBoolean(data->isOutOfOrder)); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("eventBody"), JSString(data->eventBody.c_str())); + result->ToObject()->Set(JSString("isOutOfOrder"), JSBoolean(data->isOutOfOrder)); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnUpdateActive)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnUpdateActive)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -286,13 +286,13 @@ void ResipClientSubscriptionHandler::onUpdateExtensionIsolated(void* user_data) if (_handleOnUpdateExtension) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); - result->ToObject()->Set(JSLiteral("eventBody"), JSString(data->eventBody.c_str())); - result->ToObject()->Set(JSLiteral("isOutOfOrder"), JSBoolean(data->isOutOfOrder)); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("eventBody"), JSString(data->eventBody.c_str())); + result->ToObject()->Set(JSString("isOutOfOrder"), JSBoolean(data->isOutOfOrder)); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnUpdateExtension)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnUpdateExtension)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -304,10 +304,10 @@ void ResipClientSubscriptionHandler::onTerminatedIsolated(void* user_data) if (_handleOnTerminated) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnTerminated)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnTerminated)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -354,10 +354,10 @@ void ResipClientSubscriptionHandler::onNewSubscriptionIsolated(void* user_data) if (_handleOnNewSubscription) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnNewSubscription)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnNewSubscription)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } @@ -377,10 +377,10 @@ void ResipClientSubscriptionHandler::onNotifyNotReceivedIsolated(void* user_data if (_handleOnNotifyNotReceived) { JSLocalValueHandle result = JSObject(); - result->ToObject()->Set(JSLiteral("key"), JSString(data->key.c_str())); + result->ToObject()->Set(JSString("key"), JSString(data->key.c_str())); JSLocalArgumentVector args; args.push_back(result); - (*_handleOnNotifyNotReceived)->Call(js_get_global(), args.size(), args.data()); + (*_handleOnNotifyNotReceived)->Call(js_get_v8_global(), args.size(), args.data()); } delete data; } diff --git a/src/js/modules/resip_ua/ResipDialogUsageManager.cpp b/src/js/modules/resip_ua/ResipDialogUsageManager.cpp index 48ce302ca6..b36446aafd 100644 --- a/src/js/modules/resip_ua/ResipDialogUsageManager.cpp +++ b/src/js/modules/resip_ua/ResipDialogUsageManager.cpp @@ -111,30 +111,30 @@ class SendClientRegistration : public resip::DumCommand JS_METHOD_IMPL(ResipDialogUsageManager::sendClientSubscription) { - js_method_arg_declare_self(ResipDialogUsageManager, self); - js_method_arg_declare_unwrapped_object(ResipUserProfile, profile, 0); - js_method_arg_declare_string(aor, 1); - js_method_arg_declare_string(event, 2); - js_method_arg_declare_uint32(subscriptionTime, 3); - js_method_arg_declare_int32(refreshInterval, 4); + js_method_declare_self(ResipDialogUsageManager, self); + js_method_declare_unwrapped_object(ResipUserProfile, profile, 0); + js_method_declare_string(aor, 1); + js_method_declare_string(event, 2); + js_method_declare_uint32(subscriptionTime, 3); + js_method_declare_int32(refreshInterval, 4); Token eventToken(event.c_str()); Uri uri(aor.c_str()); SendClientSubscription* cmd = new SendClientSubscription(eventToken, *self, profile->profile(), uri, subscriptionTime, refreshInterval); self->dum()->post(cmd); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipDialogUsageManager::sendClientRegistration) { - js_method_arg_declare_self(ResipDialogUsageManager, self); - js_method_arg_declare_unwrapped_object(ResipUserProfile, profile, 0); - js_method_arg_declare_string(aor, 1); + js_method_declare_self(ResipDialogUsageManager, self); + js_method_declare_unwrapped_object(ResipUserProfile, profile, 0); + js_method_declare_string(aor, 1); Uri uri(aor.c_str()); SendClientRegistration* cmd = new SendClientRegistration(*self, profile->profile(), uri); self->dum()->post(cmd); - return JSUndefined(); + js_method_set_return_undefined(); } JS_CLASS_INTERFACE(ResipDialogUsageManager, "DialogUsageManager") @@ -173,71 +173,71 @@ void ResipDialogUsageManager::onDumCanBeDeleted() JS_CONSTRUCTOR_IMPL(ResipDialogUsageManager) { OSS::JS::JSIsolate::getIsolate()->setForceAsync(true); - js_method_arg_declare_object(sipstack_object, 0); + js_method_declare_object(sipstack_object, 0); ResipSIPStack* sipstack = js_unwrap_object(ResipSIPStack, sipstack_object->ToObject()); assert(sipstack); ResipDialogUsageManager* object = new ResipDialogUsageManager(); object->_dum = new DialogUsageManager(*sipstack->stack()); - std::auto_ptr clam(new resip::ClientAuthManager()); + std::unique_ptr clam(new resip::ClientAuthManager()); object->_dum->setClientAuthManager(clam); object->_thread = new DumThread(*object->_dum); - object->Wrap(js_method_arg_self()); - return js_method_arg_self(); + object->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(ResipDialogUsageManager::run) { - js_method_arg_declare_self(ResipDialogUsageManager, self); + js_method_declare_self(ResipDialogUsageManager, self); self->_thread->run(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipDialogUsageManager::shutdown) { - js_method_arg_declare_self(ResipDialogUsageManager, self); + js_method_declare_self(ResipDialogUsageManager, self); self->_dum->shutdown(self); self->_thread->shutdown(); self->_thread->join(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipDialogUsageManager::setMasterProfile) { - js_method_arg_declare_self(ResipDialogUsageManager, self); - js_method_arg_declare_unwrapped_object(ResipMasterProfile, profile, 0); + js_method_declare_self(ResipDialogUsageManager, self); + js_method_declare_unwrapped_object(ResipMasterProfile, profile, 0); self->dum()->setMasterProfile(profile->profile()); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipDialogUsageManager::addClientSubscriptionHandler) { - js_method_arg_declare_self(ResipDialogUsageManager, self); - js_method_arg_declare_string(event, 0); - js_method_arg_declare_unwrapped_object(ResipClientSubscriptionHandler, handler, 1); + js_method_declare_self(ResipDialogUsageManager, self); + js_method_declare_string(event, 0); + js_method_declare_unwrapped_object(ResipClientSubscriptionHandler, handler, 1); self->dum()->addClientSubscriptionHandler(event.c_str(), handler->handler()); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipDialogUsageManager::setClientRegistrationHandler) { - js_method_arg_declare_self(ResipDialogUsageManager, self); - js_method_arg_declare_unwrapped_object(ResipClientRegistrationHandler, handler, 0); + js_method_declare_self(ResipDialogUsageManager, self); + js_method_declare_unwrapped_object(ResipClientRegistrationHandler, handler, 0); self->dum()->setClientRegistrationHandler(handler->handler()); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipDialogUsageManager::overrideContact) { // This is only necessary if the user agent is running behind a NAT. - js_method_arg_declare_self(ResipDialogUsageManager, self); - js_method_arg_declare_string(host, 0); - js_method_arg_declare_uint32(port, 1); + js_method_declare_self(ResipDialogUsageManager, self); + js_method_declare_string(host, 0); + js_method_declare_uint32(port, 1); Uri contact; contact.host() = Data(host.c_str()); contact.port() = port; SharedPtr feature(new ResipOverrideContact(contact, *(self->dum()), self->dum()->dumOutgoingTarget())); self->dum()->addOutgoingFeature(feature); - return JSUndefined(); + js_method_set_return_undefined(); } \ No newline at end of file diff --git a/src/js/modules/resip_ua/ResipMasterProfile.cpp b/src/js/modules/resip_ua/ResipMasterProfile.cpp index e247386a3e..55e10c5d44 100644 --- a/src/js/modules/resip_ua/ResipMasterProfile.cpp +++ b/src/js/modules/resip_ua/ResipMasterProfile.cpp @@ -38,76 +38,76 @@ JS_CONSTRUCTOR_IMPL(ResipMasterProfile) { ResipMasterProfile* object = new ResipMasterProfile(); object->_profile = resip::SharedPtr(new resip::MasterProfile()); - object->Wrap(js_method_arg_self()); - return js_method_arg_self(); + object->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(ResipMasterProfile::addSupportedMethod) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_int32(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_int32(value, 0); MethodTypes method_type = (MethodTypes)value; self->profile()->addSupportedMethod(method_type); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::addAllowedEvent) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_string(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_string(value, 0); Token token(value.c_str()); self->profile()->addAllowedEvent(token); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::validateAcceptEnabled) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_bool(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_bool(value, 0); self->profile()->validateAcceptEnabled() = value; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::validateContentEnabled) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_bool(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_bool(value, 0); self->profile()->validateContentEnabled() = value; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::setUserAgent) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_string(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_string(value, 0); self->profile()->setUserAgent(value.c_str()); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::setOutboundProxy) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_string(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_string(value, 0); Uri uri(Data(value.c_str())); self->profile()->setOutboundProxy(uri); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::setDefaultFrom) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_string(value, 0); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_string(value, 0); NameAddr aor(Data(value.c_str())); self->profile()->setDefaultFrom(aor); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipMasterProfile::setDigestCredential) { - js_method_arg_declare_self(ResipMasterProfile, self); - js_method_arg_declare_string(realm, 0); - js_method_arg_declare_string(user, 1); - js_method_arg_declare_string(password, 2); + js_method_declare_self(ResipMasterProfile, self); + js_method_declare_string(realm, 0); + js_method_declare_string(user, 1); + js_method_declare_string(password, 2); self->profile()->setDigestCredential(realm.c_str(), user.c_str(), password.c_str()); - return JSUndefined(); + js_method_set_return_undefined(); } \ No newline at end of file diff --git a/src/js/modules/resip_ua/ResipSipStack.cpp b/src/js/modules/resip_ua/ResipSipStack.cpp index 4e85bec391..954c2d7f09 100644 --- a/src/js/modules/resip_ua/ResipSipStack.cpp +++ b/src/js/modules/resip_ua/ResipSipStack.cpp @@ -50,34 +50,34 @@ JS_CONSTRUCTOR_IMPL(ResipSIPStack) object->_interruptor = new EventThreadInterruptor(*object->_pollGrp); object->_stack = new SipStack(0, DnsStub::EmptyNameserverList, object->_interruptor, false, 0, 0, object->_pollGrp); object->_thread = new EventStackThread(*object->_stack, *object->_interruptor, *object->_pollGrp); - object->Wrap(js_method_arg_self()); - return js_method_arg_self(); + object->Wrap(js_method_self()); + return js_method_self(); } JS_METHOD_IMPL(ResipSIPStack::run) { - js_method_arg_declare_self(ResipSIPStack, stack); + js_method_declare_self(ResipSIPStack, stack); stack->_stack->run(); stack->_thread->run(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipSIPStack::shutdown) { - js_method_arg_declare_self(ResipSIPStack, stack); + js_method_declare_self(ResipSIPStack, stack); stack->_stack->shutdownAndJoinThreads(); stack->_thread->shutdown(); stack->_thread->join(); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipSIPStack::addTransport) { - js_method_arg_declare_self(ResipSIPStack, self); - js_method_arg_declare_int32(type, 0); - js_method_arg_declare_uint32(port, 1); + js_method_declare_self(ResipSIPStack, self); + js_method_declare_int32(type, 0); + js_method_declare_uint32(port, 1); assert(self); TransportType transport_type = (TransportType)type; self->stack()->addTransport(transport_type, port); - return JSUndefined(); + js_method_set_return_undefined(); } \ No newline at end of file diff --git a/src/js/modules/resip_ua/ResipUserProfile.cpp b/src/js/modules/resip_ua/ResipUserProfile.cpp index 4c59dbfd7c..6801d0ea81 100644 --- a/src/js/modules/resip_ua/ResipUserProfile.cpp +++ b/src/js/modules/resip_ua/ResipUserProfile.cpp @@ -32,25 +32,25 @@ JS_CONSTRUCTOR_IMPL(ResipUserProfile) { ResipUserProfile* object = new ResipUserProfile(); object->_profile = resip::SharedPtr(new resip::UserProfile()); - object->Wrap(js_method_arg_self()); - return js_method_arg_self(); + object->Wrap(js_method_self()); + js_method_set_return_self(); } JS_METHOD_IMPL(ResipUserProfile::setDefaultFrom) { - js_method_arg_declare_self(ResipUserProfile, self); - js_method_arg_declare_string(value, 0); + js_method_declare_self(ResipUserProfile, self); + js_method_declare_string(value, 0); NameAddr aor(Data(value.c_str())); self->profile()->setDefaultFrom(aor); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(ResipUserProfile::setDigestCredential) { - js_method_arg_declare_self(ResipUserProfile, self); - js_method_arg_declare_string(realm, 0); - js_method_arg_declare_string(user, 1); - js_method_arg_declare_string(password, 2); + js_method_declare_self(ResipUserProfile, self); + js_method_declare_string(realm, 0); + js_method_declare_string(user, 1); + js_method_declare_string(password, 2); self->profile()->setDigestCredential(realm.c_str(), user.c_str(), password.c_str()); - return JSUndefined(); + js_method_set_return_undefined(); } \ No newline at end of file diff --git a/src/js/modules/resip_ua/resip_ua.cpp b/src/js/modules/resip_ua/resip_ua.cpp index 0be6834e7a..4429a87bea 100644 --- a/src/js/modules/resip_ua/resip_ua.cpp +++ b/src/js/modules/resip_ua/resip_ua.cpp @@ -108,9 +108,9 @@ static ResipLogger _logger; JS_METHOD_IMPL(set_log_level) { - js_method_arg_declare_int32(level, 0); + js_method_declare_int32(level, 0); Log::initialize(Log::OnlyExternalNoHeaders, (Log::Level)level, "oss_core", _logger); - return JSUndefined(); + js_method_set_return_undefined(); } JS_EXPORTS_INIT() diff --git a/src/js/modules/sbc-hook/sbc_hook.cpp b/src/js/modules/sbc-hook/sbc_hook.cpp index 6ec3966af9..6c5ad24239 100644 --- a/src/js/modules/sbc-hook/sbc_hook.cpp +++ b/src/js/modules/sbc-hook/sbc_hook.cpp @@ -46,136 +46,143 @@ namespace SIP { namespace SBC { -typedef v8::Handle jsval; -typedef v8::Arguments jsargs; -typedef v8::String jsstring; -typedef v8::String::Utf8Value jsstringutf8; -typedef v8::FunctionTemplate jsfunc; -#define jsvoid v8::Undefined -typedef v8::Boolean jsbool; -typedef v8::Integer jsint; -typedef v8::Number jsdouble; -typedef v8::HandleScope jsscope; -typedef v8::Handle jsfield; static SBCManager* _pSBCManager = 0; -OSS::SIP::SIPMessage* unwrapRequest(const jsargs& args) +OSS::SIP::SIPMessage* unwrapRequest(JSCallbackInfo _args_) { - if (args.Length() < 1) + if (_args_.Length() < 1) return 0; - jsval obj = args[0]; + JSValueHandle obj = _args_[0]; if (!obj->IsObject()) return 0; - jsfield field = jsfield::Cast(obj->ToObject()->GetInternalField(0)); + JSExternalHandle field = JSExternalHandle::Cast(obj->ToObject(js_method_context()).ToLocalChecked()->GetInternalField(0)); void* ptr = field->Value(); return static_cast(ptr); } -std::string jsvalToString(const jsval& str) +std::string jsvalToString(JSCallbackInfo _args_, int index) { - if (!str->IsString()) + if (!_args_[index]->IsString()) return ""; - jsstringutf8 value(str); + v8::String::Utf8Value value(js_method_isolate(),_args_[index]); return *value; } -bool jsvalToBoolean(const jsval& str) +bool jsvalToBoolean(JSCallbackInfo _args_, int index) { - if (!str->IsBoolean()) + if (!_args_[index]->IsBoolean()) return false; - return str->IsTrue();; + return _args_[index]->IsTrue(); } -int jsvalToInt(const jsval& str) +int jsvalToInt(JSCallbackInfo _args_, int index) { - if (!str->IsNumber()) + if (!_args_[index]->IsNumber()) return 0; - return str->Int32Value(); + return _args_[index]->Int32Value(js_method_context()).ToChecked(); } -static jsval msgRouteByAOR(const jsargs& args) +JS_METHOD_IMPL(msgRouteByAOR) { if (!_pSBCManager) { - return jsbool::New(false); + js_method_set_return_false(); + return; } bool userComparisonOnly = true; - if (args.Length() == 2) + if (_args_.Length() == 2) { - userComparisonOnly = args[1]->IsTrue(); + userComparisonOnly = _args_[1]->IsTrue(); } - jsscope scope; - OSS::SIP::SIPMessage* pMsg = unwrapRequest(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = unwrapRequest(_args_); if (!pMsg) { - return jsbool::New(false); + js_method_set_return_false(); + return; } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn) { - return jsbool::New(false); + js_method_set_return_false(); + return; } if (!_pSBCManager) { - return jsbool::New(false); + js_method_set_return_false(); + return; } OSS::Net::IPAddress localInterface; OSS::Net::IPAddress target; - return jsbool::New(_pSBCManager->onRouteByAOR(pMsg, pTrn, userComparisonOnly, localInterface, target)); + js_method_set_return_boolean(_pSBCManager->onRouteByAOR(pMsg, pTrn, userComparisonOnly, localInterface, target)); } -static jsval msgRouteByRURI(const jsargs& args) +JS_METHOD_IMPL(msgRouteByRURI) { if (!_pSBCManager) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - jsscope scope; - OSS::SIP::SIPMessage* pMsg = unwrapRequest(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = unwrapRequest(_args_); if (!pMsg) { - return jsbool::New(false); + js_method_set_return_false(); + return; } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn) { - return jsbool::New(false); + js_method_set_return_false(); + return; } if (!_pSBCManager) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - return jsbool::New(_pSBCManager->onRouteByRURI(pMsg, pTrn)); + js_method_set_return_boolean(_pSBCManager->onRouteByRURI(pMsg, pTrn)); } -static jsval msgResetMaxForwards(const jsargs& args) +JS_METHOD_IMPL(msgResetMaxForwards) { - if (args.Length() < 2) - return jsbool::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - jsscope scope; - OSS::SIP::SIPMessage* pMsg = unwrapRequest(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = unwrapRequest(_args_); if (!pMsg) - return jsbool::New(false); + { + js_method_set_return_false(); + return; + } - std::string maxForwards = jsvalToString(args[1]); + std::string maxForwards = jsvalToString(_args_,1); if (maxForwards.empty()) - return jsbool::New(false); + { + js_method_set_return_false(); + return; + } if (!_pSBCManager) { - return jsbool::New(false); + js_method_set_return_false(); + return; } // // First check if we are not spiraling by checking the via address @@ -195,39 +202,48 @@ static jsval msgResetMaxForwards(const jsargs& args) OSS::Net::IPAddress address(OSS::Net::IPAddress::fromV4IPPort(sentBy.c_str())); if (_pSBCManager->isLocalTransport(transport, address)) - return jsbool::New(false); + { + js_method_set_return_false(); + return; + } } } pMsg->hdrSet("Max-Forwards", maxForwards); - return jsbool::New(true); + js_method_set_return_true(); } -jsval sbc_jsexec_async(const jsargs& args) +JS_METHOD_IMPL(sbc_jsexec_async) { - if (args.Length() < 2) - return jsvoid(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - std::string bin = jsvalToString(args[0]); - std::string commandArgs = jsvalToString(args[1]); + std::string bin = jsvalToString(_args_,0); + std::string commandArgs = jsvalToString(_args_,1); #if OSS_OS_FAMILY_WINDOWS return jsvoid(); #else std::ostringstream cmd; cmd << bin << " " << commandArgs; - return jsint::New(system(cmd.str().c_str())); + js_method_set_return_integer(system(cmd.str().c_str())); #endif } -jsval sbc_jsexec(const jsargs& args) +JS_METHOD_IMPL(sbc_jsexec) { - if (args.Length() < 2) - return jsvoid(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - std::string bin = jsvalToString(args[0]); - std::string commandArgs = jsvalToString(args[1]); + std::string bin = jsvalToString(_args_,0); + std::string commandArgs = jsvalToString(_args_,1); std::ostringstream cmd; cmd << bin << " " << commandArgs; std::string command = cmd.str(); @@ -236,7 +252,10 @@ jsval sbc_jsexec(const jsargs& args) std::string result; result.reserve(1024); if (!fd) - return jsvoid(); + { + js_method_set_return_undefined(); + return; + } while (true) { int c = fgetc(fd); @@ -246,137 +265,152 @@ jsval sbc_jsexec(const jsargs& args) pclose(fd); } - return jsstring::New(result.c_str()); + js_method_set_return_string(result.c_str()); #else - return jsvoid(); + js_method_set_return_undefined(); #endif } -jsval sbc_white_list_address(const jsargs& args) +JS_METHOD_IMPL(sbc_white_list_address) { - if (args.Length() < 1) - return jsbool::New(false); + if (_args_.Length() < 1) + { + js_method_set_return_false(); + return; + } - std::string entry = jsvalToString(args[0]); + std::string entry = jsvalToString(_args_,0); boost::system::error_code ec; boost::asio::ip::address ip = boost::asio::ip::address::from_string(entry, ec); if (!ec) { SIPTransportSession::rateLimit().whiteListAddress(ip); - return jsbool::New(true); + js_method_set_return_true(); + return; } - return jsbool::New(false); + js_method_set_return_false(); } -jsval sbc_white_list_network(const jsargs& args) +JS_METHOD_IMPL(sbc_white_list_network) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return jsvoid(); + js_method_set_return_undefined(); + return; } - std::string network = jsvalToString(args[0]); + std::string network = jsvalToString(_args_,0); if (!network.empty()) { SIPTransportSession::rateLimit().whiteListNetwork(network); } - return jsvoid(); + js_method_set_return_undefined(); } -jsval sbc_deny_all_incoming(const jsargs& args) +JS_METHOD_IMPL(sbc_deny_all_incoming) { - if (args.Length() < 1) - return jsbool::New(false); + if (_args_.Length() < 1) + { + js_method_set_return_false(); + return; + } - bool deny = jsvalToBoolean(args[0]); + bool deny = jsvalToBoolean(_args_,0); SIPTransportSession::rateLimit().denyAll(deny); - return jsbool::New(true); + js_method_set_return_true(); } -jsval sbc_set_transport_threshold(const jsargs& args) +JS_METHOD_IMPL(sbc_set_transport_threshold) { - if (!_pSBCManager || args.Length() < 3) + if (!_pSBCManager || _args_.Length() < 3) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - int packetsPerSecondThreshold = jsvalToInt(args[0]); - int thresholdViolationRate = jsvalToInt(args[1]); - int banLifeTime = jsvalToInt(args[2]); + int packetsPerSecondThreshold = jsvalToInt(_args_,0); + int thresholdViolationRate = jsvalToInt(_args_,1); + int banLifeTime = jsvalToInt(_args_,2); _pSBCManager->transactionManager().stack().setTransportThreshold(packetsPerSecondThreshold, thresholdViolationRate, banLifeTime); - return jsbool::New(true); + js_method_set_return_true(); } -jsval sbc_add_channel_limit(const jsargs& args) +JS_METHOD_IMPL(sbc_add_channel_limit) { - if (!_pSBCManager || args.Length() < 2) + if (!_pSBCManager || _args_.Length() < 2) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - std::string prefix = jsvalToString(args[0]); - unsigned int limit = jsvalToInt(args[1]); + std::string prefix = jsvalToString(_args_,0); + unsigned int limit = jsvalToInt(_args_,1); _pSBCManager->cdr().channelLimits().registerDialPrefix(prefix, limit); - return jsbool::New(true); + js_method_set_return_true(); } -jsval sbc_add_domain_channel_limit(const jsargs& args) +JS_METHOD_IMPL(sbc_add_domain_channel_limit) { - if (!_pSBCManager || args.Length() < 2) + if (!_pSBCManager || _args_.Length() < 2) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - std::string domain = jsvalToString(args[0]); - unsigned int limit = jsvalToInt(args[1]); + std::string domain = jsvalToString(_args_,0); + unsigned int limit = jsvalToInt(_args_,1); _pSBCManager->cdr().domainLimits().registerDomain(domain, limit); - return jsbool::New(true); + js_method_set_return_true(); } -jsval sbc_get_channel_count(const jsargs& args) +JS_METHOD_IMPL(sbc_get_channel_count) { - if (!_pSBCManager || args.Length() < 1) + if (!_pSBCManager || _args_.Length() < 1) { - return jsint::New(0); + js_method_set_return_integer(0); + return; } - std::string prefix = jsvalToString(args[0]); - return jsint::New(_pSBCManager->cdr().channelLimits().getCallCount(prefix)); + std::string prefix = jsvalToString(_args_,0); + js_method_set_return_integer(_pSBCManager->cdr().channelLimits().getCallCount(prefix)); } -jsval sbc_get_domain_channel_count(const jsargs& args) +JS_METHOD_IMPL(sbc_get_domain_channel_count) { - if (!_pSBCManager || args.Length() < 1) + if (!_pSBCManager || _args_.Length() < 1) { - return jsint::New(0); + js_method_set_return_integer(0); + return; } - std::string domain = jsvalToString(args[0]); - return jsint::New(_pSBCManager->cdr().domainLimits().getCallCount(domain)); + std::string domain = jsvalToString(_args_,0); + js_method_set_return_integer(_pSBCManager->cdr().domainLimits().getCallCount(domain)); } -jsval sbc_set_log_level(const jsargs& args) +JS_METHOD_IMPL(sbc_set_log_level) { - if (args.Length() < 1) + if (_args_.Length() < 1) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - std::string sLogLevel = jsvalToString(args[0]);; + std::string sLogLevel = jsvalToString(_args_,0);; if (sLogLevel.empty()) { - return jsbool::New(false); + js_method_set_return_false(); + return; } if (sLogLevel == "fatal")// A fatal error. The application will most likely terminate. This is the highest priority. @@ -413,72 +447,77 @@ jsval sbc_set_log_level(const jsargs& args) } else { - return jsbool::New(false); + js_method_set_return_false(); + return; } - return jsbool::New(true); + js_method_set_return_true(); } -jsval sbc_ban_user_id(const jsargs& args) +JS_METHOD_IMPL(sbc_ban_user_id) { - if (!_pSBCManager || args.Length() < 1) + if (!_pSBCManager || _args_.Length() < 1) { - return jsvoid(); + js_method_set_return_undefined(); + return; } - std::string val = jsvalToString(args[0]); + std::string val = jsvalToString(_args_,0); if (!val.empty()) { _pSBCManager->autoBanRules().banUserById(val); } - return jsvoid(); + js_method_set_return_undefined(); } -jsval sbc_ban_user_display(const jsargs& args) +JS_METHOD_IMPL(sbc_ban_user_display) { - if (!_pSBCManager || args.Length() < 1) + if (!_pSBCManager || _args_.Length() < 1) { - return jsvoid(); + js_method_set_return_undefined(); + return; } - std::string val = jsvalToString(args[0]); + std::string val = jsvalToString(_args_,0); if (!val.empty()) { _pSBCManager->autoBanRules().banUserByDisplayName(val); } - return jsvoid(); + js_method_set_return_undefined(); } -jsval sbc_ban_user_agent(const jsargs& args) +JS_METHOD_IMPL(sbc_ban_user_agent) { - if (!_pSBCManager || args.Length() < 1) + if (!_pSBCManager || _args_.Length() < 1) { - return jsvoid(); + js_method_set_return_undefined(); + return; } - std::string val = jsvalToString(args[0]); + std::string val = jsvalToString(_args_,0); if (!val.empty()) { _pSBCManager->autoBanRules().banUserAgent(val); } - return jsvoid(); + js_method_set_return_undefined(); } -jsval sbc_run(const jsargs& args) +JS_METHOD_IMPL(sbc_run) { - return jsbool::New(_pSBCManager->run()); + js_method_set_return_boolean(_pSBCManager->run()); } -jsval sbc_start_options_keep_alive(const jsargs& args) +JS_METHOD_IMPL(sbc_start_options_keep_alive) { - if (!_pSBCManager || args.Length() < 1) + if (!_pSBCManager || _args_.Length() < 1) { - return jsbool::New(false); + js_method_set_return_false(); + return; } - bool start = jsvalToBoolean(args[0]); + bool start = jsvalToBoolean(_args_,0); _pSBCManager->registerHandler()->pauseKeepAlive(!start); - return jsbool::New(true); + js_method_set_return_true(); } } } } // OSS::SIP::SBC diff --git a/src/js/modules/sip-parser/sip_parser.cpp b/src/js/modules/sip-parser/sip_parser.cpp index 51aad5b69a..09f7100565 100644 --- a/src/js/modules/sip-parser/sip_parser.cpp +++ b/src/js/modules/sip-parser/sip_parser.cpp @@ -42,717 +42,958 @@ using namespace OSS::SIP; using B2BUA::SIPB2BTransaction; -static /*size_t*/ v8::Handle msgGetMethod(const v8::Arguments& args/*const char* headerName*/) +JS_METHOD_IMPL(msgGetMethod) { - if (args.Length() != 1) - return v8::Undefined(); + if (_args_.Length() != 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { std::string cseq = pMsg->hdrGet(OSS::SIP::HDR_CSEQ); OSS::SIP::SIPCSeq hCSeq(cseq.c_str()); - return v8::String::New(hCSeq.getMethod().c_str()); + js_method_set_return_string(hCSeq.getMethod().c_str()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgGetMethod - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*size_t*/ v8::Handle msgHdrPresent(const v8::Arguments& args/*const char* headerName*/) +JS_METHOD_IMPL(msgHdrPresent) { - if (args.Length() != 2) - return v8::Undefined(); + if (_args_.Length() != 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->hdrPresent(headerName.c_str())); + js_method_set_return_boolean(pMsg->hdrPresent(headerName.c_str())); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrPresent - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*size_t*/ v8::Handle msgHdrGetSize(const v8::Arguments& args/*const char* headerName*/) +JS_METHOD_IMPL(msgHdrGetSize) { - if (args.Length() != 2) - return v8::Undefined(); + if (_args_.Length() != 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Integer::New(pMsg->hdrGetSize(headerName.c_str())); + js_method_set_return_integer(pMsg->hdrGetSize(headerName.c_str())); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrGetSize - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*const std::string&*/ v8::Handle msgHdrGet(const v8::Arguments& args/*const char* headerName, size_t index = 0*/) +JS_METHOD_IMPL(msgHdrGet) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - if (args.Length() > 2) + if (_args_.Length() > 2) { - size_t index = args[2]->NumberValue(); - return v8::String::New(pMsg->hdrGet(headerName.c_str(), index).c_str()); + size_t index = _args_[2]->NumberValue(js_method_context()).ToChecked(); + js_method_set_return_string(pMsg->hdrGet(headerName.c_str(), index).c_str()); + return; } - return v8::String::New(pMsg->hdrGet(headerName.c_str()).c_str()); + js_method_set_return_string(pMsg->hdrGet(headerName.c_str()).c_str()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrGet - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*bool*/ v8::Handle msgHdrSet(const v8::Arguments& args/*const char* headerName, const std::string& headerValue, size_t index*/) +JS_METHOD_IMPL(msgHdrSet) { - if (args.Length() < 3) - return v8::Boolean::New(false); + if (_args_.Length() < 3) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerValue = OSS::JS::string_from_js_string(args[2]); + std::string headerValue = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (headerValue.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } size_t index = 0; - if (args.Length() > 3) - index = args[3]->NumberValue(); + if (_args_.Length() > 3) + index = _args_[3]->NumberValue(js_method_context()).ToChecked(); try { - return v8::Boolean::New(pMsg->hdrSet(headerName.c_str(), headerValue, index)); + js_method_set_return_boolean(pMsg->hdrSet(headerName.c_str(), headerValue, index)); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrSet - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*bool*/ v8::Handle msgHdrRemove(const v8::Arguments& args/*const char* headerName*/) +JS_METHOD_IMPL(msgHdrRemove) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { - return v8::Boolean::New(pMsg->hdrRemove(headerName.c_str())); + js_method_set_return_boolean(pMsg->hdrRemove(headerName.c_str())); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrRemove - " << e.message(); OSS::log_error(msg.str()); - return v8::Boolean::New(false); + js_method_set_return_false(); } } -static /*bool*/ v8::Handle msgHdrListAppend(const v8::Arguments& args/*const char* name, const std::string& value*/) +JS_METHOD_IMPL(msgHdrListAppend) { - if (args.Length() < 3) - return v8::Boolean::New(false); + if (_args_.Length() < 3) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerValue = OSS::JS::string_from_js_string(args[2]); + std::string headerValue = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (headerValue.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { - return v8::Boolean::New(pMsg->hdrListAppend(headerName.c_str(), headerValue)); + js_method_set_return_boolean(pMsg->hdrListAppend(headerName.c_str(), headerValue)); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrListAppend - " << e.message(); OSS::log_error(msg.str()); - return v8::Boolean::New(false); + js_method_set_return_false(); } } -static /*bool*/ v8::Handle msgHdrListPrepend(const v8::Arguments& args/*const char* name, const std::string& value*/) +JS_METHOD_IMPL(msgHdrListPrepend) { - if (args.Length() < 3) - return v8::Boolean::New(false); + if (_args_.Length() < 3) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerValue = OSS::JS::string_from_js_string(args[2]); + std::string headerValue = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (headerValue.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { - return v8::Boolean::New(pMsg->hdrListPrepend(headerName.c_str(), headerValue)); + js_method_set_return_boolean(pMsg->hdrListPrepend(headerName.c_str(), headerValue)); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrListPrepend - " << e.message(); OSS::log_error(msg.str()); - return v8::Boolean::New(false); + js_method_set_return_false(); } } -static /*std::string*/ v8::Handle msgHdrListPopFront(const v8::Arguments& args/*const char* name*/) +JS_METHOD_IMPL(msgHdrListPopFront) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::String::New(pMsg->hdrListPopFront(headerName.c_str()).c_str()); + js_method_set_return_string(pMsg->hdrListPopFront(headerName.c_str()).c_str()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrListPopFront - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*bool*/ v8::Handle msgHdrListRemove(const v8::Arguments& args/*const char* name*/) +JS_METHOD_IMPL(msgHdrListRemove) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string headerName = OSS::JS::string_from_js_string(args[1]); + std::string headerName = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (headerName.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { - return v8::Boolean::New(pMsg->hdrListRemove(headerName.c_str())); + js_method_set_return_boolean(pMsg->hdrListRemove(headerName.c_str())); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrListRemove - " << e.message(); OSS::log_error(msg.str()); - return v8::Boolean::New(false); + js_method_set_return_false(); } } -static /*boost::tribool*/ v8::Handle msgIsRequest(const v8::Arguments& args/*const char* method = 0*/) +JS_METHOD_IMPL(msgIsRequest) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string method; - if (args.Length() >= 2) - method = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() >= 2) + method = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); try { if (method.empty()) - return v8::Boolean::New(pMsg->isRequest()); + { + js_method_set_return_boolean(pMsg->isRequest()); + return; + } else - return v8::Boolean::New(pMsg->isRequest(method.c_str())); + { + js_method_set_return_boolean(pMsg->isRequest(method.c_str())); + return; + } } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIsRequest - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIsResponse(const v8::Arguments& args) +JS_METHOD_IMPL(msgIsResponse) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->isResponse()); + js_method_set_return_boolean(pMsg->isResponse()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIsResponse - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIs1xx(const v8::Arguments& args) +JS_METHOD_IMPL(msgIs1xx) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->is1xx()); + js_method_set_return_boolean(pMsg->is1xx()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIs1xx - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIs2xx(const v8::Arguments& args) +JS_METHOD_IMPL(msgIs2xx) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->is2xx()); + js_method_set_return_boolean(pMsg->is2xx()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIs2xx - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIs3xx(const v8::Arguments& args) +JS_METHOD_IMPL(msgIs3xx) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->is3xx()); + js_method_set_return_boolean(pMsg->is3xx()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIs3xx - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIs4xx(const v8::Arguments& args) +JS_METHOD_IMPL(msgIs4xx) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->is4xx()); + js_method_set_return_boolean(pMsg->is4xx()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIs4xx - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIs5xx(const v8::Arguments& args) +JS_METHOD_IMPL(msgIs5xx) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->is5xx()); + js_method_set_return_boolean(pMsg->is5xx()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIs5xx - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIs6xx(const v8::Arguments& args) +JS_METHOD_IMPL(msgIs6xx) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->is6xx()); + js_method_set_return_boolean(pMsg->is6xx()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIs6xx - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIsResponseFamily(const v8::Arguments& args/*int responseCode*/) +JS_METHOD_IMPL(msgIsResponseFamily) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - int responseCode = args[1]->NumberValue(); + int responseCode = _args_[1]->NumberValue(js_method_context()).ToChecked(); try { - return v8::Boolean::New(pMsg->isResponseFamily(responseCode)); + js_method_set_return_boolean(pMsg->isResponseFamily(responseCode)); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIsResponseFamily - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIsErrorResponse(const v8::Arguments& args) +JS_METHOD_IMPL(msgIsErrorResponse) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->isErrorResponse()); + js_method_set_return_boolean(pMsg->isErrorResponse()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgIsErrorResponse - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*boost::tribool*/ v8::Handle msgIsMidDialog(const v8::Arguments& args) +JS_METHOD_IMPL(msgIsMidDialog) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } try { - return v8::Boolean::New(pMsg->isMidDialog()); + js_method_set_return_boolean(pMsg->isMidDialog()); } catch(const OSS::Exception& e) { std::ostringstream msg; msg << "JavaScript->C++ Exception: msgHdrGet - " << e.message(); OSS::log_error(msg.str()); - return v8::Undefined(); + js_method_set_return_undefined(); } } -static /*std::string&*/ v8::Handle msgGetBody(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetBody) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - return v8::String::New(pMsg->getBody().c_str()); + js_method_set_return_string(pMsg->getBody().c_str()); } -static /*bool*/ v8::Handle msgSetBody(const v8::Arguments& args/*const std::string& body*/) +JS_METHOD_IMPL(msgSetBody) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string body = OSS::JS::string_from_js_string(args[1]); + std::string body = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); pMsg->setBody(body); - return v8::Boolean::New(true); + js_method_set_return_true(); } -static /*std::string&*/ v8::Handle msgGetStartLine(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetStartLine) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - return v8::String::New(pMsg->getStartLine().c_str()); + js_method_set_return_string(pMsg->getStartLine().c_str()); } -static /*std::string&*/ v8::Handle msgSetStartLine(const v8::Arguments& args/*const std::string& sline*/) +JS_METHOD_IMPL(msgSetStartLine) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string sline = OSS::JS::string_from_js_string(args[1]); + std::string sline = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); pMsg->setStartLine(sline); - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle msgGetData(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetData) { - if (args.Length() < 1) - return v8::Undefined(); - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); - return v8::String::New(pMsg->data().c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(pMsg->data().c_str()); } -static v8::Handle msgGetSize(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetSize) { - if (args.Length() < 1) - return v8::Undefined(); - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Integer::New(0); - return v8::Integer::New(pMsg->data().size()); + { + js_method_set_return_integer(0); + return; + } + js_method_set_return_integer(pMsg->data().size()); } -static v8::Handle msgCommitData(const v8::Arguments& args) +JS_METHOD_IMPL(msgCommitData) { - if (args.Length() < 1) - return v8::Undefined(); - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } pMsg->commitData(); - return v8::String::New(pMsg->data().c_str()); + js_method_set_return_string(pMsg->data().c_str()); } // // Request-Line Processing // -static /*bool*/ v8::Handle requestLineGetMethod(const v8::Arguments& args/*const std::string& rline, std::string& method*/) +JS_METHOD_IMPL(requestLineGetMethod) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; if (OSS::SIP::SIPRequestLine::getMethod(input, result)) - return v8::String::New(result.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(result.c_str()); + return; + } + js_method_set_return_undefined(); } -static /*bool*/ v8::Handle requestLineGetURI(const v8::Arguments& args/*const std::string& rline, std::string& uri*/) +JS_METHOD_IMPL(requestLineGetURI) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; if (OSS::SIP::SIPRequestLine::getURI(input, result)) - return v8::String::New(result.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(result.c_str()); + return; + } + js_method_set_return_undefined(); } -static /*bool*/ v8::Handle requestLineGetVersion(const v8::Arguments& args/*const std::string& rline, std::string& version*/) +JS_METHOD_IMPL(requestLineGetVersion) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; if (OSS::SIP::SIPRequestLine::getVersion(input, result)) - return v8::String::New(result.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(result.c_str()); + return; + } + js_method_set_return_undefined(); } -static /*bool*/ v8::Handle requestLineSetMethod(const v8::Arguments& args/*std::string& rline, const char* method*/) +JS_METHOD_IMPL(requestLineSetMethod) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); - return v8::Boolean::New(OSS::SIP::SIPRequestLine::setMethod(input, newval.c_str())); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + js_method_set_return_boolean(OSS::SIP::SIPRequestLine::setMethod(input, newval.c_str())); } -static /*bool*/ v8::Handle requestLineSetURI(const v8::Arguments& args/*std::string& rline, const char* uri*/) +JS_METHOD_IMPL(requestLineSetURI) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (!OSS::SIP::SIPRequestLine::setURI(input, newval.c_str())) - return v8::Undefined(); - return v8::String::New(input.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(input.c_str()); } -static /*bool*/ v8::Handle requestLineSetVersion(const v8::Arguments& args/*std::string& rline, const char* version*/) +JS_METHOD_IMPL(requestLineSetVersion) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); - return v8::Boolean::New(OSS::SIP::SIPRequestLine::setVersion(input, newval.c_str())); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + js_method_set_return_boolean(OSS::SIP::SIPRequestLine::setVersion(input, newval.c_str())); } @@ -760,466 +1001,676 @@ static /*bool*/ v8::Handle requestLineSetVersion(const v8::Arguments& // Status-Line Processing // -static v8::Handle/*bool*/ statusLineGetVersion(const v8::Arguments& args/*const std::string& sline, std::string& version*/) +JS_METHOD_IMPL(statusLineGetVersion) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; if (OSS::SIP::SIPStatusLine::getVersion(input, result)) - return v8::String::New(result.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(result.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ statusLineSetVersion(const v8::Arguments& args/*std::string& sline, const char* version*/) +JS_METHOD_IMPL(statusLineSetVersion) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); - return v8::Boolean::New(OSS::SIP::SIPStatusLine::setVersion(input, newval.c_str())); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + js_method_set_return_boolean(OSS::SIP::SIPStatusLine::setVersion(input, newval.c_str())); } -static v8::Handle/*bool*/ statusLineGetStatusCode(const v8::Arguments& args/*const std::string& sline,std::string& statusCode*/) +JS_METHOD_IMPL(statusLineGetStatusCode) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; if (OSS::SIP::SIPStatusLine::getStatusCode(input, result)) - return v8::String::New(result.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(result.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ statusLineSetStatusCode(const v8::Arguments& args/*std::string& sline, const char* statusCode*/) +JS_METHOD_IMPL(statusLineSetStatusCode) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); - return v8::Boolean::New(OSS::SIP::SIPStatusLine::setStatusCode(input, newval.c_str())); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + js_method_set_return_boolean(OSS::SIP::SIPStatusLine::setStatusCode(input, newval.c_str())); } -static v8::Handle/*bool*/ statusLineGetReasonPhrase(const v8::Arguments& args/*const std::string& sline, std::string& reasonPhrase*/) +JS_METHOD_IMPL(statusLineGetReasonPhrase) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; - if (OSS::SIP::SIPStatusLine::getReasonPhrase(input, result)) - return v8::String::New(result.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(result.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ statusLineSetReasonPhrase(const v8::Arguments& args/*std::string& sline, const char* reasonPhrase*/) +JS_METHOD_IMPL(statusLineSetReasonPhrase) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); - return v8::Boolean::New(OSS::SIP::SIPStatusLine::setReasonPhrase(input, newval.c_str())); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + js_method_set_return_boolean(OSS::SIP::SIPStatusLine::setReasonPhrase(input, newval.c_str())); } // // URI Processing // -static v8::Handle/*bool*/ uriSetScheme(const v8::Arguments& args/*std::string& uri, const char* scheme*/) +JS_METHOD_IMPL(uriSetScheme) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPURI::setScheme(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriGetScheme(const v8::Arguments& args/*const std::string& uri, std::string& value*/) +JS_METHOD_IMPL(uriGetScheme) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPURI::getScheme(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriGetUser(const v8::Arguments& args/*const std::string& uri, std::string& value*/) +JS_METHOD_IMPL(uriGetUser) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPURI::getUser(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriSetUserInfo(const v8::Arguments& args/*std::string& uri, const char* userInfo*/) +JS_METHOD_IMPL(uriSetUserInfo) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPURI::setUserInfo(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriGetPassword(const v8::Arguments& args/*const std::string& uri, std::string& value*/) +JS_METHOD_IMPL(uriGetPassword) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPURI::getPassword(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriGetHostPort(const v8::Arguments& args/*const std::string& uri, std::string& value*/) +JS_METHOD_IMPL(uriGetHostPort) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPURI::getHostPort(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriSetHostPort(const v8::Arguments& args/*std::string& uri, const char* hostPort*/) +JS_METHOD_IMPL(uriSetHostPort) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPURI::setHostPort(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriGetParams(const v8::Arguments& args/*const std::string& uri, std::string& params*/) +JS_METHOD_IMPL(uriGetParams) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPURI::getParams(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriSetParams(const v8::Arguments& args/*std::string& uri, const std::string& params*/) +JS_METHOD_IMPL(uriSetParams) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPURI::setParams(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriHasParam(const v8::Arguments& args/*const std::string& uri, const char* paraName*/) +JS_METHOD_IMPL(uriHasParam) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string val = OSS::JS::string_from_js_string(args[1]); - return v8::Boolean::New(OSS::SIP::SIPURI::hasParam(input, val.c_str())); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string val = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + js_method_set_return_boolean(OSS::SIP::SIPURI::hasParam(input, val.c_str())); } -static v8::Handle/*bool*/ uriGetParam(const v8::Arguments& args/*const std::string& uri, const char* paramName, std::string& paramValue*/) +JS_METHOD_IMPL(uriGetParam) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); std::string value; if (OSS::SIP::SIPURI::getParam(input, name.c_str(), value)) - return v8::String::New(value.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(value.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriGetParamEx(const v8::Arguments& args/*const std::string& params, const char* paramName, std::string& paramValue*/) +JS_METHOD_IMPL(uriGetParamEx) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); std::string value; if (OSS::SIP::SIPURI::getParamEx(input, name.c_str(), value)) - return v8::String::New(value.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(value.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriSetParam(const v8::Arguments& args/*std::string& uri, const char* paramName, const char* paramValue*/) +JS_METHOD_IMPL(uriSetParam) { - if (args.Length() < 3) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); - std::string newval = OSS::JS::string_from_js_string(args[2]); - return v8::Boolean::New(OSS::SIP::SIPURI::setParam(input, name.c_str(), newval.c_str())); + if (_args_.Length() < 3) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); + js_method_set_return_boolean(OSS::SIP::SIPURI::setParam(input, name.c_str(), newval.c_str())); } -static v8::Handle/*bool*/ uriSetParamEx(const v8::Arguments& args/*std::string& params, const char* paramName, const char* paramValue*/) +JS_METHOD_IMPL(uriSetParamEx) { - if (args.Length() < 3) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); - std::string newval = OSS::JS::string_from_js_string(args[2]); - return v8::Boolean::New(OSS::SIP::SIPURI::setParam(input, name.c_str(), newval.c_str())); + if (_args_.Length() < 3) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); + js_method_set_return_boolean(OSS::SIP::SIPURI::setParam(input, name.c_str(), newval.c_str())); } -static v8::Handle/*void*/ uriEscapeUser(const v8::Arguments& args/*std::string& result, const char* user*/) +JS_METHOD_IMPL(uriEscapeUser) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; OSS::SIP::SIPURI::escapeUser(result, input.c_str()); - return v8::String::New(result.c_str()); + js_method_set_return_string(result.c_str()); } -static v8::Handle/*void*/ uriEscapeParam(const v8::Arguments& args/*std::string& result, const char* param*/) +JS_METHOD_IMPL(uriEscapeParam) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string result; OSS::SIP::SIPURI::escapeParam(result, input.c_str()); - return v8::String::New(result.c_str()); + js_method_set_return_string(result.c_str()); } -static v8::Handle/*bool*/ uriGetHeaders(const v8::Arguments& args/*const std::string& uri, std::string& headers*/) +JS_METHOD_IMPL(uriGetHeaders) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPURI::getHeaders(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriSetHeaders(const v8::Arguments& args/*std::string& uri, const std::string& headers*/) +JS_METHOD_IMPL(uriSetHeaders) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPURI::setHeaders(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle/*bool*/ uriVerify(const v8::Arguments& args/*const char* uri*/) +JS_METHOD_IMPL(uriVerify) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - return v8::Boolean::New(OSS::SIP::SIPURI::verify(input.c_str())); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + js_method_set_return_boolean(OSS::SIP::SIPURI::verify(input.c_str())); } // // From Processing // -static v8::Handle /*bool*/ fromGetDisplayName(const v8::Arguments& args/*const std::string& from, std::string& displayName*/) +JS_METHOD_IMPL(fromGetDisplayName) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPFrom::getDisplayName(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromSetDisplayName(const v8::Arguments& args/*std::string& from, const char* uri*/) +JS_METHOD_IMPL(fromSetDisplayName) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPFrom::setDisplayName(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromGetURI(const v8::Arguments& args/*const std::string& from, std::string& uri*/) +JS_METHOD_IMPL(fromGetURI) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPFrom::getURI(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromSetURI(const v8::Arguments& args/*std::string& from, const char* uri*/) +JS_METHOD_IMPL(fromSetURI) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPFrom::setURI(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromGetHeaderParams(const v8::Arguments& args/*const std::string& from, std::string& headerParams*/) +JS_METHOD_IMPL(fromGetHeaderParams) { - if (args.Length() < 1) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); std::string val; if (OSS::SIP::SIPFrom::getHeaderParams(input, val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromSetHeaderParams(const v8::Arguments& args/*std::string& from, const char* headerParams*/) +JS_METHOD_IMPL(fromSetHeaderParams) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string newval = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (OSS::SIP::SIPFrom::setHeaderParams(input, newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromGetHeaderParam(const v8::Arguments& args/*const std::string& from, const char* paramName, std::string& paramValue*/) +JS_METHOD_IMPL(fromGetHeaderParam) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); std::string val; if (OSS::SIP::SIPFrom::getHeaderParam(input, name.c_str(), val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromGetHeaderParamEx(const v8::Arguments& args/*const std::string& headerParams, const char* paramName, std::string& paramValue*/) +JS_METHOD_IMPL(fromGetHeaderParamEx) { - if (args.Length() < 2) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); std::string val; if (OSS::SIP::SIPFrom::getHeaderParamEx(input, name.c_str(), val)) - return v8::String::New(val.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(val.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromSetHeaderParam(const v8::Arguments& args/*std::string& from, const char* paramName, const char* paramValue*/) +JS_METHOD_IMPL(fromSetHeaderParam) { - if (args.Length() < 3) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); - std::string newval = OSS::JS::string_from_js_string(args[2]); + if (_args_.Length() < 3) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (OSS::SIP::SIPFrom::setHeaderParam(input, name.c_str(), newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle /*bool*/ fromSetHeaderParamEx(const v8::Arguments& args/*std::string& headerParams, const char* paramName, const char* paramValue*/) +JS_METHOD_IMPL(fromSetHeaderParamEx) { - if (args.Length() < 3) - return v8::Undefined(); - std::string input = OSS::JS::string_from_js_string(args[0]); - std::string name = OSS::JS::string_from_js_string(args[1]); - std::string newval = OSS::JS::string_from_js_string(args[2]); + if (_args_.Length() < 3) + { + js_method_set_return_undefined(); + return; + } + std::string input = OSS::JS::string_from_js_string( js_method_isolate(), _args_[0]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + std::string newval = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (OSS::SIP::SIPFrom::setHeaderParamEx(input, name.c_str(), newval.c_str())) - return v8::String::New(input.c_str()); - return v8::Undefined(); + { + js_method_set_return_string(input.c_str()); + return; + } + js_method_set_return_undefined(); } -static v8::Handle msgGetRequestUri(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetRequestUri) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string requestURI; if (SIPRequestLine::getURI(pMsg->startLine(), requestURI)) { - return v8::String::New(requestURI.c_str()); + js_method_set_return_string(requestURI.c_str()); + return; } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle msgSetRequestUri(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetRequestUri) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string uri = OSS::JS::string_from_js_string(args[1]); + std::string uri = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); try { - return v8::Boolean::New(SIPRequestLine::setURI(pMsg->startLine(), uri.c_str())); + js_method_set_return_boolean(SIPRequestLine::setURI(pMsg->startLine(), uri.c_str())); } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); } } -static v8::Handle msgGetRequestUriUser(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetRequestUriUser) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string requestURI; if (SIPRequestLine::getURI(pMsg->startLine(), requestURI)) { std::string user; if (SIPURI::getUser(requestURI, user)) - return v8::String::New(user.c_str()); + { + js_method_set_return_string(user.c_str()); + return; + } } - return v8::String::New(""); + js_method_set_return_string(""); } -static v8::Handle msgSetRequestUriUser(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetRequestUriUser) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string user = OSS::JS::string_from_js_string(args[1]); + std::string user = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); try { @@ -1228,49 +1679,72 @@ static v8::Handle msgSetRequestUriUser(const v8::Arguments& args) { SIPURI::setUserInfo(requestURI, user.c_str()); if (SIPRequestLine::setURI(pMsg->startLine(), requestURI.c_str())) - return v8::Boolean::New(true); + { + js_method_set_return_true(); + return; + } else - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } } } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); + return; } - return v8::Boolean::New(false); + + js_method_set_return_false(); } -static v8::Handle msgGetRequestUriHostPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetRequestUriHostPort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string requestURI; if (SIPRequestLine::getURI(pMsg->startLine(), requestURI)) { std::string hostPort; if (SIPURI::getHostPort(requestURI, hostPort)) - return v8::String::New(hostPort.c_str()); + { + js_method_set_return_string(hostPort.c_str()); + return; + } } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle msgSetRequestUriHostPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetRequestUriHostPort) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string hostPort = OSS::JS::string_from_js_string(args[1]); + std::string hostPort = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); try { @@ -1279,89 +1753,129 @@ static v8::Handle msgSetRequestUriHostPort(const v8::Arguments& args) { SIPURI::setHostPort(requestURI, hostPort.c_str()); if (SIPRequestLine::setURI(pMsg->startLine(), requestURI.c_str())) - return v8::Boolean::New(true); + { + js_method_set_return_true(); + return; + } else - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } } } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); + return; } - return v8::Boolean::New(false); + js_method_set_return_false(); } -static v8::Handle msgGetRequestUriHost(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetRequestUriHost) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string requestURI; if (SIPRequestLine::getURI(pMsg->startLine(), requestURI)) { std::string host; if (SIPURI::getHost(requestURI, host)) - return v8::String::New(host.c_str()); + { + js_method_set_return_string(host.c_str()); + return; + } } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle msgGetRequestUriPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetRequestUriPort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string requestURI; if (SIPRequestLine::getURI(pMsg->startLine(), requestURI)) { std::string port; if (SIPURI::getPort(requestURI, port)) - return v8::String::New(port.c_str()); + { + js_method_set_return_string(port.c_str()); + return; + } } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle msgGetRequestUriParameters(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetRequestUriParameters) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string requestURI; if (SIPRequestLine::getURI(pMsg->startLine(), requestURI)) { std::string params; if (SIPURI::getParams(requestURI, params)) - return v8::String::New(params.c_str()); + { + js_method_set_return_string(params.c_str()); + return; + } } - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle msgSetRequestUriParameters(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetRequestUriParameters) { - if (args.Length() < 2) - return v8::Boolean::New(false); + if (_args_.Length() < 2) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string params = OSS::JS::string_from_js_string(args[1]); + std::string params = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); try { @@ -1373,278 +1887,406 @@ static v8::Handle msgSetRequestUriParameters(const v8::Arguments& arg } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); + return; } - return v8::Boolean::New(true); + js_method_set_return_true(); } -v8::Handle msgGetToUser(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetToUser) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string to = pMsg->hdrGet(OSS::SIP::HDR_TO); std::string user; if (!SIPFrom::getUser(to, user)) - return v8::Undefined(); - return v8::String::New(user.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(user.c_str()); } -v8::Handle msgSetToUser(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetToUser) { - if (args.Length() < 1) - return v8::Boolean::New(false); + if (_args_.Length() < 1) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { std::string to = pMsg->hdrGet(OSS::SIP::HDR_TO); - std::string user = OSS::JS::string_from_js_string(args[1]); + std::string user = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (!SIPFrom::setUser(to, user.c_str())) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } if (!pMsg->hdrSet(OSS::SIP::HDR_TO, to.c_str())) - return v8::Boolean::New(false); - return v8::Boolean::New(true); + { + js_method_set_return_false(); + return; + } + js_method_set_return_true(); } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); } } -v8::Handle msgGetToHostPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetToHostPort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string to = pMsg->hdrGet(OSS::SIP::HDR_TO); std::string hostPort; if (!SIPFrom::getHostPort(to, hostPort)) - return v8::Undefined(); - return v8::String::New(hostPort.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(hostPort.c_str()); } -v8::Handle msgGetToHost(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetToHost) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string to = pMsg->hdrGet(OSS::SIP::HDR_TO); std::string host; if (!SIPFrom::getHost(to, host)) - return v8::Undefined(); - return v8::String::New(host.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(host.c_str()); } -v8::Handle msgGetToPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetToPort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string to = pMsg->hdrGet(OSS::SIP::HDR_TO); std::string host; if (!SIPFrom::getHostPort(to, host)) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::vector tokens = OSS::string_tokenize(host, ":"); if (tokens.size() <= 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - return v8::String::New(tokens[1].c_str()); + js_method_set_return_string(tokens[1].c_str()); } -v8::Handle msgSetToHostPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetToHostPort) { - if (args.Length() < 1) - return v8::Boolean::New(false); + if (_args_.Length() < 1) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { std::string to = pMsg->hdrGet(OSS::SIP::HDR_TO); - std::string hostPort = OSS::JS::string_from_js_string(args[1]); + std::string hostPort = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (!SIPFrom::setHostPort(to, hostPort.c_str())) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } if (!pMsg->hdrSet(OSS::SIP::HDR_TO, to.c_str())) - return v8::Boolean::New(false); - return v8::Boolean::New(true); + { + js_method_set_return_false(); + return; + } + js_method_set_return_true(); } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); } } -v8::Handle msgGetFromUser(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetFromUser) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string to = pMsg->hdrGet(OSS::SIP::HDR_FROM); std::string user; if (!SIPFrom::getUser(to, user)) - return v8::Undefined(); - return v8::String::New(user.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(user.c_str()); } -v8::Handle msgSetFromUser(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetFromUser) { - if (args.Length() < 1) - return v8::Boolean::New(false); + if (_args_.Length() < 1) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { std::string from = pMsg->hdrGet(OSS::SIP::HDR_FROM); - std::string user = OSS::JS::string_from_js_string(args[1]); + std::string user = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (!SIPFrom::setUser(from, user.c_str())) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } if (!pMsg->hdrSet(OSS::SIP::HDR_FROM, from.c_str())) - return v8::Boolean::New(false); - return v8::Boolean::New(true); + { + js_method_set_return_false(); + return; + } + js_method_set_return_true(); } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); } } -v8::Handle msgGetFromHostPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetFromHostPort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string to = pMsg->hdrGet(OSS::SIP::HDR_FROM); std::string hostPort; if (!SIPFrom::getHostPort(to, hostPort)) - return v8::Undefined(); - return v8::String::New(hostPort.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(hostPort.c_str()); } -v8::Handle msgGetFromHost(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetFromHost) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string from = pMsg->hdrGet(OSS::SIP::HDR_FROM); std::string host; if (!SIPFrom::getHost(from, host)) - return v8::Undefined(); - return v8::String::New(host.c_str()); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_string(host.c_str()); } -v8::Handle msgGetFromPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetFromPort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string from = pMsg->hdrGet(OSS::SIP::HDR_FROM); std::string host; if (!SIPFrom::getHostPort(from, host)) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::vector tokens = OSS::string_tokenize(host, ":"); if (tokens.size() <= 1) { - return v8::Undefined(); + js_method_set_return_undefined(); + return; } - return v8::String::New(tokens[1].c_str()); + js_method_set_return_string(tokens[1].c_str()); } -v8::Handle msgSetFromHostPort(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetFromHostPort) { - if (args.Length() < 1) - return v8::Boolean::New(false); + if (_args_.Length() < 1) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } try { std::string from = pMsg->hdrGet(OSS::SIP::HDR_FROM); - std::string hostPort = OSS::JS::string_from_js_string(args[1]); + std::string hostPort = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (!SIPFrom::setHostPort(from, hostPort.c_str())) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } if (!pMsg->hdrSet(OSS::SIP::HDR_FROM, from.c_str())) - return v8::Boolean::New(false); - return v8::Boolean::New(true); + js_method_set_return_true(); } catch(...) { - return v8::Boolean::New(false); + js_method_set_return_false(); } } -v8::Handle msgGetContactUri(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetContactUri) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string hContactList = pMsg->hdrGet(OSS::SIP::HDR_CONTACT); if (hContactList.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } ContactURI contact; if (!hContactList.empty()) @@ -1652,26 +2294,38 @@ v8::Handle msgGetContactUri(const v8::Arguments& args) std::string contactUri = contact.getURI(); - return v8::String::New(contactUri.c_str()); + js_method_set_return_string(contactUri.c_str()); } -v8::Handle msgGetContactParameter(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetContactParameter) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string param = OSS::JS::string_from_js_string(args[1]); + std::string param = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (param.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string hContactList = pMsg->hdrGet(OSS::SIP::HDR_CONTACT); if (hContactList.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } ContactURI contact; if (!hContactList.empty()) @@ -1679,22 +2333,31 @@ v8::Handle msgGetContactParameter(const v8::Arguments& args) std::string value = contact.getHeaderParam(param.c_str()); if (value.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - return v8::String::New(value.c_str()); + js_method_set_return_string(value.c_str()); } -v8::Handle msgGetAuthenticator(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetAuthenticator) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string realm = OSS::JS::string_from_js_string(args[1]); + std::string realm = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); OSS::string_to_lower(realm); int wwwAuthSize = pMsg->hdrGetSize(OSS::SIP::HDR_AUTHORIZATION); @@ -1754,176 +2417,254 @@ v8::Handle msgGetAuthenticator(const v8::Arguments& args) } } - return v8::String::New(authenticator.c_str()); + js_method_set_return_string(authenticator.c_str()); } -static v8::Handle msgSetTransactionProperty(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetTransactionProperty) { - if (args.Length() < 3) - return v8::Boolean::New(false); + if (_args_.Length() < 3) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string name = OSS::JS::string_from_js_string(args[1]); - std::string value = OSS::JS::string_from_js_string(args[2]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + std::string value = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (name.empty() || value.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } pTrn->setProperty(name, value); - return v8::Boolean::New(true); + js_method_set_return_true(); } -static v8::Handle msgGetTransactionProperty(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetTransactionProperty) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string name = OSS::JS::string_from_js_string(args[1]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (name.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string value; if (name == "log-id") value = pTrn->getLogId(); else pTrn->getProperty(name, value); - return v8::String::New(value.c_str()); + js_method_set_return_string(value.c_str()); } -static v8::Handle msgSetProperty(const v8::Arguments& args) +JS_METHOD_IMPL(msgSetProperty) { - if (args.Length() < 3) - return v8::Boolean::New(false); + if (_args_.Length() < 3) + { + js_method_set_return_false(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } - std::string name = OSS::JS::string_from_js_string(args[1]); - std::string value = OSS::JS::string_from_js_string(args[2]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); + std::string value = OSS::JS::string_from_js_string( js_method_isolate(), _args_[2]); if (name.empty() || value.empty()) - return v8::Boolean::New(false); + { + js_method_set_return_false(); + return; + } pMsg->setProperty(name, value); - return v8::Boolean::New(true); + js_method_set_return_true(); } -static v8::Handle msgGetProperty(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetProperty) { - if (args.Length() < 2) - return v8::Undefined(); + if (_args_.Length() < 2) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } - std::string name = OSS::JS::string_from_js_string(args[1]); + std::string name = OSS::JS::string_from_js_string( js_method_isolate(), _args_[1]); if (name.empty()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } std::string value; pMsg->getProperty(name, value); - return v8::String::New(value.c_str()); + js_method_set_return_string(value.c_str()); } -static v8::Handle msgGetSourceAddress(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetSourceAddress) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn || !pTrn->serverTransport()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } OSS::Net::IPAddress addr = pTrn->serverTransport()->getRemoteAddress(); - return v8::String::New(addr.toString().c_str()); + js_method_set_return_string(addr.toString().c_str()); } -static v8::Handle msgGetSourcePort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetSourcePort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn || !pTrn->serverTransport()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } OSS::Net::IPAddress addr = pTrn->serverTransport()->getRemoteAddress(); - return v8::Integer::New(addr.getPort()); + js_method_set_return_integer(addr.getPort()); } -static v8::Handle msgGetInterfaceAddress(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetInterfaceAddress) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn || !pTrn->serverTransport()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } OSS::Net::IPAddress addr = pTrn->serverTransport()->getLocalAddress(); - return v8::String::New(addr.toString().c_str()); + js_method_set_return_string(addr.toString().c_str()); } -static v8::Handle msgGetInterfacePort(const v8::Arguments& args) +JS_METHOD_IMPL(msgGetInterfacePort) { - if (args.Length() < 1) - return v8::Undefined(); + if (_args_.Length() < 1) + { + js_method_set_return_undefined(); + return; + } - v8::HandleScope scope; - OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(args); + js_method_enter_scope(); + OSS::SIP::SIPMessage* pMsg = OSS::JS::unwrap_external_object(_args_); if (!pMsg) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } SIPB2BTransaction* pTrn = static_cast(pMsg->userData()); if (!pTrn || !pTrn->serverTransport()) - return v8::Undefined(); + { + js_method_set_return_undefined(); + return; + } OSS::Net::IPAddress addr = pTrn->serverTransport()->getLocalAddress(); - return v8::Integer::New(addr.getPort()); + js_method_set_return_integer(addr.getPort()); } JS_EXPORTS_INIT() diff --git a/src/js/modules/socket/inet_socket.cpp b/src/js/modules/socket/inet_socket.cpp index daea4d6bb0..e5e550fd8f 100644 --- a/src/js/modules/socket/inet_socket.cpp +++ b/src/js/modules/socket/inet_socket.cpp @@ -34,7 +34,7 @@ static char SERVICE_BUF[SERVICE_BUF_SIZE]; JS_METHOD_IMPL(__create_inet_stream_socket) { - js_method_arg_assert_size_eq(4); + js_method_args_assert_size_eq(4); js_method_arg_assert_string(0); js_method_arg_assert_string(1); js_method_arg_assert_uint32(2); @@ -47,12 +47,12 @@ JS_METHOD_IMPL(__create_inet_stream_socket) int ret = create_inet_stream_socket(host.c_str(), service.c_str(), proto, flags); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__create_inet_dgram_socket) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_uint32(0); js_method_arg_assert_int32(1); @@ -61,12 +61,12 @@ JS_METHOD_IMPL(__create_inet_dgram_socket) int ret = create_inet_dgram_socket(proto, flags); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__sendto_inet_dgram_socket) { - js_method_arg_assert_size_eq(6); + js_method_args_assert_size_eq(6); js_method_arg_assert_int32(0); js_method_arg_assert_buffer(1); @@ -76,7 +76,7 @@ JS_METHOD_IMPL(__sendto_inet_dgram_socket) js_method_arg_assert_int32(5); int32_t fd = js_method_arg_as_int32(0); - BufferObject* pBuffer = js_method_arg_unwrap_object(BufferObject, 1); + BufferObject* pBuffer = js_method_unwrap_object(BufferObject, 1); uint32_t size = js_method_arg_as_uint32(2); std::string host = js_method_arg_as_std_string(3); std::string service = js_method_arg_as_std_string(4); @@ -84,19 +84,19 @@ JS_METHOD_IMPL(__sendto_inet_dgram_socket) int32_t ret = sendto_inet_dgram_socket(fd, pBuffer->buffer().data(), size, host.c_str(), service.c_str(), flags); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__recvfrom_inet_dgram_socket) { - js_method_arg_assert_size_eq(4); + js_method_args_assert_size_eq(4); js_method_arg_assert_int32(0); js_method_arg_assert_buffer(1); js_method_arg_assert_uint32(2); js_method_arg_assert_int32(3); int32_t fd = js_method_arg_as_int32(0); - BufferObject* pBuffer = js_method_arg_unwrap_object(BufferObject, 1); + BufferObject* pBuffer = js_method_unwrap_object(BufferObject, 1); uint32_t size = js_method_arg_as_uint32(2); int32_t flags = js_method_arg_as_int32(3); @@ -104,18 +104,18 @@ JS_METHOD_IMPL(__recvfrom_inet_dgram_socket) memset(SERVICE_BUF, 0, SERVICE_BUF_SIZE); uint32_t ret = recvfrom_inet_dgram_socket(fd, (void*)pBuffer->buffer().data(), size, HOST_BUF, HOST_BUF_SIZE, SERVICE_BUF, SERVICE_BUF_SIZE, flags, LIBSOCKET_NUMERIC); - JSObjectHandle result = JSObject(); - result->Set(JSLiteral("size"), JSUInt32(ret)); - result->Set(JSLiteral("host"), JSString(HOST_BUF)); - result->Set(JSLiteral("port"), JSString(SERVICE_BUF)); - result->Set(JSLiteral("buffer"), js_method_arg(1)); + JSObjectHandle result = js_method_object(); + result->Set(js_method_context(), js_method_string("size"), js_method_uint32(ret)); + result->Set(js_method_context(), js_method_string("host"), js_method_string(HOST_BUF)); + result->Set(js_method_context(), js_method_string("port"), js_method_string(SERVICE_BUF)); + result->Set(js_method_context(), js_method_string("buffer"), js_method_arg(1)); - return result; + js_method_set_return_handle(result); } JS_METHOD_IMPL(__connect_inet_dgram_socket) { - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_int32(0); js_method_arg_assert_string(1); js_method_arg_assert_string(2); @@ -126,32 +126,32 @@ JS_METHOD_IMPL(__connect_inet_dgram_socket) int32_t ret = connect_inet_dgram_socket(fd, host.c_str(), service.c_str()); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__destroy_inet_socket) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int32_t fd = js_method_arg_as_int32(0); int32_t ret = destroy_inet_socket(fd); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__shutdown_inet_stream_socket) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_int32(0); js_method_arg_assert_int32(1); int32_t fd = js_method_arg_as_int32(0); int32_t method = js_method_arg_as_int32(1); int32_t ret = shutdown_inet_stream_socket(fd, method); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__create_inet_server_socket) { - js_method_arg_assert_size_eq(5); + js_method_args_assert_size_eq(5); js_method_arg_assert_string(0); js_method_arg_assert_string(1); js_method_arg_assert_uint32(2); @@ -166,12 +166,12 @@ JS_METHOD_IMPL(__create_inet_server_socket) int32_t ret = create_inet_server_socket(host.c_str(), service.c_str(), proto, family, flags); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } JS_METHOD_IMPL(__accept_inet_stream_socket) { - js_method_arg_assert_size_eq(2); + js_method_args_assert_size_eq(2); js_method_arg_assert_int32(0); js_method_arg_assert_int32(1); @@ -182,29 +182,29 @@ JS_METHOD_IMPL(__accept_inet_stream_socket) memset(SERVICE_BUF, 0, SERVICE_BUF_SIZE); int32_t cfd = accept_inet_stream_socket(fd, HOST_BUF, HOST_BUF_SIZE, SERVICE_BUF, SERVICE_BUF_SIZE, LIBSOCKET_NUMERIC, flags); - JSObjectHandle result = JSObject(); - result->Set(JSLiteral("fd"), JSInt32(cfd)); + JSObjectHandle result = js_method_object(); + result->Set(js_method_context(), js_method_string("fd"), js_method_int32(cfd)); if (cfd != -1) { - result->Set(JSLiteral("host"), JSString(HOST_BUF)); - result->Set(JSLiteral("port"), JSString(SERVICE_BUF)); + result->Set(js_method_context(), js_method_string("host"), js_method_string(HOST_BUF)); + result->Set(js_method_context(), js_method_string("port"), js_method_string(SERVICE_BUF)); } - return result; + js_method_set_return_handle(result); } JS_METHOD_IMPL(__get_address_family) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_string(0); std::string host = js_method_arg_as_std_string(0); int32_t ret = get_address_family(host.c_str()); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } #if !defined(__APPLE__) JS_METHOD_IMPL(__create_multicast_socket) { - js_method_arg_assert_size_eq(3); + js_method_args_assert_size_eq(3); js_method_arg_assert_string(0); js_method_arg_assert_string(1); js_method_arg_assert_string(2); @@ -215,14 +215,13 @@ JS_METHOD_IMPL(__create_multicast_socket) int32_t ret = create_multicast_socket(group.c_str(), port.c_str(), ifname.c_str()); - - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); } #endif JS_METHOD_IMPL(__getpeername) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int32_t fd = js_method_arg_as_int32(0); @@ -234,7 +233,8 @@ JS_METHOD_IMPL(__getpeername) len = sizeof addr; if (getpeername(fd, (struct sockaddr*)&addr, &len) == -1) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } if (addr.ss_family == AF_INET) @@ -250,15 +250,15 @@ JS_METHOD_IMPL(__getpeername) inet_ntop(AF_INET6, &s->sin6_addr, host, sizeof host); } - JSObjectHandle result = JSObject(); - result->Set(JSLiteral("host"), JSString(host)); - result->Set(JSLiteral("port"), JSString(OSS::string_from_number(port).c_str())); - return result; + JSObjectHandle result = js_method_object(); + result->Set(js_method_context(), js_method_string("host"), js_method_string(host)); + result->Set(js_method_context(), js_method_string("port"), js_method_string(OSS::string_from_number(port).c_str())); + js_method_set_return_handle(result); } JS_METHOD_IMPL(__getsockname) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int32_t fd = js_method_arg_as_int32(0); @@ -270,7 +270,8 @@ JS_METHOD_IMPL(__getsockname) len = sizeof addr; if (getsockname(fd, (struct sockaddr*)&addr, &len) == -1) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } if (addr.ss_family == AF_INET) @@ -286,10 +287,10 @@ JS_METHOD_IMPL(__getsockname) inet_ntop(AF_INET6, &s->sin6_addr, host, sizeof host); } - JSObjectHandle result = JSObject(); - result->Set(JSLiteral("host"), JSString(host)); - result->Set(JSLiteral("port"), JSString(OSS::string_from_number(port).c_str())); - return result; + JSObjectHandle result = js_method_object(); + result->Set(js_method_context(), js_method_string("host"), js_method_string(host)); + result->Set(js_method_context(), js_method_string("port"), js_method_string(OSS::string_from_number(port).c_str())); + js_method_set_return_handle(result); } JS_EXPORTS_INIT() diff --git a/src/js/modules/system/system.cpp b/src/js/modules/system/system.cpp index 7c58227cf1..527c5bef7e 100644 --- a/src/js/modules/system/system.cpp +++ b/src/js/modules/system/system.cpp @@ -12,35 +12,35 @@ JS_METHOD_IMPL(__close) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); int fd = js_method_arg_as_int32(0); - return JSInt32(::close(fd)); + js_method_set_return_handle(js_method_int32(::close(fd))); } JS_METHOD_IMPL(__exit) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); ::exit(js_method_arg_as_int32(0)); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(___exit) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_int32(0); ::_exit(js_method_arg_as_int32(0)); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__write) { - js_method_arg_assert_size_gteq(2); + js_method_args_assert_size_gteq(2); js_method_arg_assert_int32(0); int32_t fd = js_method_arg_as_int32(0); uint32_t size = 0; - if (js_method_arg_length() == 3) + if (js_method_args_length() == 3) { js_method_arg_assert_uint32(2); size = js_method_arg_as_uint32(2); @@ -49,56 +49,60 @@ JS_METHOD_IMPL(__write) if (js_method_arg_is_string(1)) { std::string data = js_method_arg_as_std_string(1); - return JSInt32(::write(fd, data.data(), size ? size : data.size())); + js_method_set_return_handle(js_method_int32(::write(fd, data.data(), size ? size : data.size()))); + return; } else if (js_method_arg_is_array(1)) { JSArrayHandle args1 = js_method_arg_as_array(1); ByteArray bytes; - if (!js_int_array_to_byte_array(args1, bytes)) + if (!js_int_array_to_byte_array(js_method_isolate(), args1, bytes)) { - return JSInt32(-1); + js_method_set_return_handle(js_method_int32(-1)); + return; } - return JSInt32(::write(fd, bytes.data(), size ? size : bytes.size())); + js_method_set_return_handle(js_method_int32(::write(fd, bytes.data(), size ? size : bytes.size()))); + return; } else if (js_method_arg_is_buffer(1)) { - BufferObject* pBuffer = js_method_arg_unwrap_object(BufferObject, 1); - return JSInt32(::write(fd, pBuffer->buffer().data(), size ? size : pBuffer->buffer().size())); + BufferObject* pBuffer = js_method_unwrap_object(BufferObject, 1); + js_method_set_return_handle(js_method_int32(::write(fd, pBuffer->buffer().data(), size ? size : pBuffer->buffer().size()))); + return; } - return JSException("Invalid Argument"); + js_method_throw("Invalid Argument"); } JS_METHOD_IMPL(__cout) { - js_method_arg_declare_string(msg, 0); + js_method_declare_string(msg, 0); std::cout << msg; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__oendl) { std::cout << std::endl; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__cerr) { - js_method_arg_declare_string(msg, 0); + js_method_declare_string(msg, 0); std::cerr << msg; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__eendl) { std::cerr << std::endl; - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__read) { - js_method_arg_assert_size_gteq(2); + js_method_args_assert_size_gteq(2); js_method_arg_assert_int32(0); js_method_arg_assert_uint32(1); @@ -106,79 +110,83 @@ JS_METHOD_IMPL(__read) int32_t fd = js_method_arg_as_int32(0); uint32_t len = js_method_arg_as_uint32(1); - if (js_method_arg_length() == 2) + if (js_method_args_length() == 2) { // // Create a new Buffer // - JSValueHandle result = BufferObject::createNew(len); - BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject()); + JSValueHandle result = BufferObject::createNew(js_method_isolate(), len); + BufferObject* pBuffer = js_unwrap_object(BufferObject, result->ToObject(js_method_context()).ToLocalChecked()); ByteArray& buf = pBuffer->buffer(); std::size_t ret = ::read(fd, buf.data(), buf.size()); if (!ret) { - return JSUndefined(); + js_method_set_return_undefined(); + return; } - return result; + js_method_set_return_handle(result); + return; } - else if (js_method_arg_length() == 3) + else if (js_method_args_length() == 3) { // // Use the provided buffer // js_method_arg_assert_buffer(2); - BufferObject* pBuffer = js_method_arg_unwrap_object(BufferObject, 2); + BufferObject* pBuffer = js_method_unwrap_object(BufferObject, 2); if (len > pBuffer->buffer().size()) { - js_throw("Length paramater exceeds buffer size"); + js_method_throw("Length paramater exceeds buffer size"); } ByteArray& buf = pBuffer->buffer(); std::size_t ret = ::read(fd, buf.data(), len); - return JSInt32(ret); + js_method_set_return_handle(js_method_int32(ret)); + return; } - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__sleep) { - js_method_arg_assert_size_eq(1); + js_method_args_assert_size_eq(1); js_method_arg_assert_uint32(0); ::sleep(js_method_arg_as_uint32(0)); - return JSUndefined(); + js_method_set_return_undefined(); } JS_METHOD_IMPL(__gc) { - v8::V8::LowMemoryNotification(); - while(!v8::V8::IdleNotification()); - return JSUndefined(); + js_method_isolate()->LowMemoryNotification(); + //while(!v8::V8::IdleNotification()); + // V8 6.5 API Changes: Do not use idle notification at all. This function has been a no-op for almost all calls for a while now. + js_method_set_return_undefined(); } JS_METHOD_IMPL(__setsid) { - return JSInt32(setsid()); + js_method_set_return_handle(js_method_int32(setsid())); } JS_METHOD_IMPL(__getdtablesize) { - return JSInt32(getdtablesize()); + js_method_set_return_handle(js_method_int32(getdtablesize())); } JS_METHOD_IMPL(__getpid) { - return JSInt32(getpid()); + js_method_set_return_handle(js_method_int32(getpid())); } JS_METHOD_IMPL(__getppid) { - return JSInt32(getppid()); + js_method_set_return_handle(js_method_int32(getppid())); } #if !defined(__APPLE__) JS_METHOD_IMPL(__thread_self) { - return JSUInt32(pthread_self()); + js_method_set_return_handle(js_method_uint32(pthread_self())); } #endif @@ -187,10 +195,11 @@ JS_METHOD_IMPL(__write_pid_file) std::string pidFile; bool exclusive = false; - int argc = js_method_arg_length(); + int argc = js_method_args_length(); if (argc < 1) { - return JSFalse; + js_method_set_return_false(); + return; } else if (argc == 1) { @@ -205,12 +214,14 @@ JS_METHOD_IMPL(__write_pid_file) int handle = open(pidFile.c_str(), O_RDWR|O_CREAT, 0600); if (handle == -1) { - return JSFalse; + js_method_set_return_false(); + return; } if (exclusive && lockf(handle,F_TLOCK,0) == -1) { - return JSFalse; + js_method_set_return_false(); + return; } pid_t pid = getpid(); @@ -219,14 +230,15 @@ JS_METHOD_IMPL(__write_pid_file) sprintf(pidStr,"%d\n", pid); if (write(handle, pidStr, strlen(pidStr)) == -1) { - return JSFalse; + js_method_set_return_false(); + return; } if (!exclusive) { close(handle); } - return JSTrue; + js_method_set_return_true(); } JS_EXPORTS_INIT() diff --git a/src/js/modules/utils/utils.cpp b/src/js/modules/utils/utils.cpp index 64cc8eae41..052dfe3d4f 100644 --- a/src/js/modules/utils/utils.cpp +++ b/src/js/modules/utils/utils.cpp @@ -4,36 +4,42 @@ JS_METHOD_IMPL(cidrVerify) { - js_method_arg_declare_string(ip, 0); - js_method_arg_declare_string(cidr, 1); + js_method_declare_string(ip, 0); + js_method_declare_string(cidr, 1); if (ip.empty() || cidr.empty()) - return JSUndefined(); - return JSBoolean(OSS::socket_address_cidr_verify(ip, cidr)); + { + js_method_set_return_undefined(); + return; + } + js_method_set_return_boolean(OSS::socket_address_cidr_verify(ip, cidr)); } JS_METHOD_IMPL(wildCardCompare) { - js_method_arg_declare_string(wild, 0); - js_method_arg_declare_string(input, 1); - return JSBoolean(OSS::string_wildcard_compare(wild.c_str(), input)); + js_method_declare_string(wild, 0); + js_method_declare_string(input, 1); + js_method_set_return_boolean(OSS::string_wildcard_compare(wild.c_str(), input)); } JS_METHOD_IMPL(isIpInRange) { - js_method_arg_declare_string(low, 0); - js_method_arg_declare_string(high, 1); - js_method_arg_declare_string(strIp, 2); + js_method_declare_string(low, 0); + js_method_declare_string(high, 1); + js_method_declare_string(strIp, 2); if (low.empty() || high.empty() || strIp.empty()) - return JSUndefined(); + { + js_method_set_return_undefined(); + return; + } - return JSBoolean(OSS::socket_address_range_verify(low, high, strIp)); + js_method_set_return_boolean(OSS::socket_address_range_verify(low, high, strIp)); } JS_METHOD_IMPL(md5Hash) { - js_method_arg_declare_string(input, 0); - return JSString(OSS::string_md5_hash(input.c_str()).c_str()); + js_method_declare_string(input, 0); + js_method_set_return_string(OSS::string_md5_hash(input.c_str()).c_str()); } JS_EXPORTS_INIT() diff --git a/src/js/modules/zmq/zmq.cpp b/src/js/modules/zmq/zmq.cpp index c30a7fd07c..304a13b870 100644 --- a/src/js/modules/zmq/zmq.cpp +++ b/src/js/modules/zmq/zmq.cpp @@ -25,7 +25,6 @@ #include "OSS/UTL/Semaphore.h" using OSS::JS::JSObjectWrap; -v8::Persistent ZMQSocketObject::_constructor; boost::thread* ZMQSocketObject::_pPollThread; typedef std::list Sockets; static Sockets _socketList; @@ -144,6 +143,7 @@ ZMQSocketObject::ZMQSocketObject(Socket::SocketType type) : { _pSocket = new Socket(type, _context); ::pipe(_pipe); + } ZMQSocketObject::~ZMQSocketObject() @@ -155,50 +155,53 @@ ZMQSocketObject::~ZMQSocketObject() } -v8::Handle ZMQSocketObject::New(const v8::Arguments& args) +JS_CONSTRUCTOR_IMPL(ZMQSocketObject) { - v8::HandleScope scope; - if (args.Length() < 1 || !args[0]->IsInt32()) + js_method_enter_scope(); + + if (_args_.Length() < 1 || !_args_[0]->IsInt32()) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument. Must provide socket type."))); + js_method_throw("Invalid Argument. Must provide socket type."); } - ZMQSocketObject* pSocket = new ZMQSocketObject((Socket::SocketType)args[0]->ToInt32()->Value()); - pSocket->Wrap(args.This()); + + ZMQSocketObject* pSocket = new ZMQSocketObject((Socket::SocketType)_args_[0]->Int32Value(js_method_context()).ToChecked()); + pSocket->Wrap(js_method_self()); - return args.This(); + js_method_set_return_self(); } -static bool __get_string_arg(const v8::Arguments& args, std::string& value) +static bool __get_string_arg(JSCallbackInfo _args_, std::string& value) { - v8::HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) + js_method_enter_scope(); + if (_args_.Length() == 0 || !_args_[0]->IsString()) { return false; } - value = *v8::String::Utf8Value(args[0]); + value = *v8::String::Utf8Value(js_method_isolate(),_args_[0]); return true; } -static bool __get_buffer_arg(const v8::Arguments& args, std::string& value) +static bool __get_buffer_arg(JSCallbackInfo _args_, std::string& value) { - v8::HandleScope scope; - if (args.Length() == 0 || !BufferObject::isBuffer(args[0])) + js_method_enter_scope(); + if (_args_.Length() == 0 || !BufferObject::isBuffer(js_method_isolate(), _args_[0])) { return false; } - BufferObject* pBuffer = JSObjectWrap::Unwrap(args[0]->ToObject()); + BufferObject* pBuffer = JSObjectWrap::Unwrap(_args_[0]->ToObject(js_method_context()).ToLocalChecked()); std::copy(pBuffer->buffer().begin(), pBuffer->buffer().end(), std::back_inserter(value)); return true; } -v8::Handle ZMQSocketObject::connect(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::connect) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + std::string arg; - if (!__get_string_arg(args, arg)) + if (!__get_string_arg(_args_, arg)) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } bool ret = pObject->_pSocket->connect(arg); @@ -208,17 +211,18 @@ v8::Handle ZMQSocketObject::connect(const v8::Arguments& args) _socketList.push_back(pObject); __wakeup_pipe(); } - return v8::Boolean::New(ret); + js_method_set_return_boolean(ret); } -v8::Handle ZMQSocketObject::bind(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::bind) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + std::string arg; - if (!__get_string_arg(args, arg)) + if (!__get_string_arg(_args_, arg)) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } bool ret = pObject->_pSocket->bind(arg); if (ret) @@ -227,119 +231,110 @@ v8::Handle ZMQSocketObject::bind(const v8::Arguments& args) _socketList.push_back(pObject); __wakeup_pipe(); } - return v8::Boolean::New(ret); + js_method_set_return_boolean(ret); } -v8::Handle ZMQSocketObject::subscribe(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::subscribe) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + std::string arg; - if (!__get_string_arg(args, arg) && !__get_buffer_arg(args, arg)) + if (!__get_string_arg(_args_, arg) && !__get_buffer_arg(_args_, arg)) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } - return v8::Boolean::New(pObject->_pSocket->subscribe(arg)); + js_method_set_return_boolean(pObject->_pSocket->subscribe(arg)); } -v8::Handle ZMQSocketObject::publish(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::publish) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + std::string arg; - if (!__get_string_arg(args, arg) && !__get_buffer_arg(args, arg)) + if (!__get_string_arg(_args_, arg) && !__get_buffer_arg(_args_, arg)) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } - return v8::Boolean::New(pObject->_pSocket->publish(arg)); + js_method_set_return_boolean(pObject->_pSocket->publish(arg)); } -v8::Handle ZMQSocketObject::send(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::send) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + std::string arg; - if (!__get_string_arg(args, arg) && !__get_buffer_arg(args, arg)) + if (!__get_string_arg(_args_, arg) && !__get_buffer_arg(_args_, arg)) { - return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Invalid Argument"))); + js_method_throw("Invalid Argument"); } - return v8::Boolean::New(pObject->_pSocket->sendRequest(arg)); + js_method_set_return_boolean(pObject->_pSocket->sendRequest(arg)); } -v8::Handle ZMQSocketObject::receive(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::receive) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + std::string msg; - v8::Handle result = v8::Undefined(); + v8::Handle result = js_method_undefined(); if (pObject->_pSocket->receiveReply(msg, 0)) { BufferObject* pBuffer = 0; - if (args.Length() == 1 && BufferObject::isBuffer(args[0])) + if (_args_.Length() == 1 && BufferObject::isBuffer(js_method_isolate(), _args_[0])) { - result = args[0]; - pBuffer = JSObjectWrap::Unwrap(args[0]->ToObject()); + result = _args_[0]; + pBuffer = JSObjectWrap::Unwrap(_args_[0]->ToObject(js_method_context()).ToLocalChecked()); if (msg.size() > pBuffer->buffer().size()) { - return v8::ThrowException(v8::Exception::Error(v8::String::New("Size of read buffer is too small"))); + js_method_throw("Size of read buffer is too small"); } std::copy(msg.begin(), msg.end(), pBuffer->buffer().begin()); } else { - return v8::ThrowException(v8::Exception::Error(v8::String::New("Read buffer not provided"))); + js_method_throw("Read buffer not provided"); } } - result->ToObject()->Set(v8::String::NewSymbol("payloadSize"), v8::Uint32::New(msg.size())); + result->ToObject(js_method_context()).ToLocalChecked()->Set(js_method_context(), js_method_string("payloadSize"), js_method_uint32(msg.size())); pObject->clearReadable(); - return result; + js_method_set_return_handle(result); } -v8::Handle ZMQSocketObject::close(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::close) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + pObject->_pSocket->close(); _socketList.remove(pObject); __wakeup_pipe(); - return v8::Undefined(); + js_method_set_return_undefined(); } -v8::Handle ZMQSocketObject::getFd(const v8::Arguments& args) +JS_METHOD_IMPL(ZMQSocketObject::getFd) { - v8::HandleScope scope; - ZMQSocketObject* pObject = JSObjectWrap::Unwrap(args.This()); - return v8::Int32::New(pObject->_pipe[0]); + js_method_enter_scope(); + ZMQSocketObject* pObject = js_method_unwrap_self(ZMQSocketObject); + + js_method_set_return_handle(js_method_int32(pObject->_pipe[0])); } -void ZMQSocketObject::Init(v8::Handle exports) +JS_CLASS_INTERFACE(ZMQSocketObject,"ZMQSocket") { - v8::HandleScope scope; - exports->Set(v8::String::New("REQ"), v8::Integer::New(Socket::REQ), v8::ReadOnly); - exports->Set(v8::String::New("REP"), v8::Integer::New(Socket::REP), v8::ReadOnly); - exports->Set(v8::String::New("PUSH"), v8::Integer::New(Socket::PUSH), v8::ReadOnly); - exports->Set(v8::String::New("PULL"), v8::Integer::New(Socket::PULL), v8::ReadOnly); - exports->Set(v8::String::New("PUB"), v8::Integer::New(Socket::PUB), v8::ReadOnly); - exports->Set(v8::String::New("SUB"), v8::Integer::New(Socket::SUB), v8::ReadOnly); - - v8::Local tpl = v8::FunctionTemplate::New(ZMQSocketObject::New); - tpl->SetClassName(v8::String::NewSymbol("ZMQSocket")); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("ObjectType"), v8::String::NewSymbol("ZMQSocket")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("connect"), v8::FunctionTemplate::New(connect)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("bind"), v8::FunctionTemplate::New(bind)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("connect"), v8::FunctionTemplate::New(connect)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("publish"), v8::FunctionTemplate::New(publish)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("subscribe"), v8::FunctionTemplate::New(subscribe)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("send"), v8::FunctionTemplate::New(send)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("receive"), v8::FunctionTemplate::New(receive)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("_close"), v8::FunctionTemplate::New(close)->GetFunction()); - tpl->PrototypeTemplate()->Set(v8::String::NewSymbol("getFd"), v8::FunctionTemplate::New(getFd)->GetFunction()); - - ZMQSocketObject::_constructor = v8::Persistent::New(tpl->GetFunction()); - exports->Set(v8::String::NewSymbol("ZMQSocket"), ZMQSocketObject::_constructor); - + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "connect", connect); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "bind", bind); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "publish", publish); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "subscribe", subscribe); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "send", send); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "receive", receive); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "close", close); + JS_CLASS_METHOD_DEFINE(ZMQSocketObject, "getFd", getFd); + + JS_CLASS_INTERFACE_END(ZMQSocketObject); + _context = new zmq::context_t(1); _notifySem = new OSS::Semaphore(); _notifyReceiver = new ZMQSocketObject(OSS::ZMQ::ZMQSocket::PULL); @@ -349,15 +344,17 @@ void ZMQSocketObject::Init(v8::Handle exports) ZMQSocketObject::_pPollThread = new boost::thread(boost::bind(pollForReadEvents)); } -static v8::Handle cleanup_exports(const v8::Arguments& args) +JS_METHOD_IMPL(cleanup_exports) { - v8::HandleScope scope; + js_method_enter_scope(); + if (_isTerminating) { // // Don't let this function be called twice or we will double free stuff // - return v8::Undefined(); + js_method_set_return_undefined(); + return; } _isTerminating = true; @@ -379,18 +376,23 @@ static v8::Handle cleanup_exports(const v8::Arguments& args) // // delete _context ; - return v8::Undefined(); + js_method_set_return_undefined(); } -static v8::Handle init_exports(const v8::Arguments& args) -{ - v8::HandleScope scope; - v8::Persistent exports = v8::Persistent::New(v8::Object::New()); - - ZMQSocketObject::Init(exports); - exports->Set(v8::String::NewSymbol("__cleanup_exports"), v8::FunctionTemplate::New(cleanup_exports)->GetFunction()); +JS_EXPORTS_INIT() +{ + js_export_class(ZMQSocketObject); + + js_export_method("__cleanup_exports",cleanup_exports); - return exports; + js_export_int32("REQ",OSS::ZMQ::ZMQSocket::REQ); + js_export_int32("REP",OSS::ZMQ::ZMQSocket::REP); + js_export_int32("PUSH",OSS::ZMQ::ZMQSocket::PUSH); + js_export_int32("PULL",OSS::ZMQ::ZMQSocket::PULL); + js_export_int32("PUB",OSS::ZMQ::ZMQSocket::PUB); + js_export_int32("SUB",OSS::ZMQ::ZMQSocket::SUB); + + js_export_finalize(); } JS_REGISTER_MODULE(JSZMQSocket); diff --git a/src/utl/CrashHandler.cpp b/src/utl/CrashHandler.cpp index 00b7fa1898..2e181a4535 100644 --- a/src/utl/CrashHandler.cpp +++ b/src/utl/CrashHandler.cpp @@ -553,7 +553,7 @@ void CrashHandler::HandleSignal(int sig, void * /* info */, void *secret) { msg[0] = 0; } - char line_no[4]; + char line_no[32]; strcat(msg, Safe::itoa(i - stackOffset, line_no)); strcat(msg, " ["); // NOLINT(runtime/printf) strcat(msg, line); // NOLINT(runtime/printf)