mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-04 19:31:56 +00:00
[mod_v8] Use upstream libnode-dev instead of custom libv8-6.1-dev on Linux. Enable for ARM64 and armhf. (#3052)
This commit is contained in:
@@ -54,7 +54,7 @@ jobs:
|
||||
shell: bash
|
||||
working-directory: freeswitch
|
||||
run: |
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y libpcre2-dev libsphinxbase-dev libpocketsphinx-dev
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y libpcre2-dev libsphinxbase-dev libpocketsphinx-dev libnode-dev
|
||||
./ci.sh -t scan-build -a configure -c sofia-sip -p "$GITHUB_WORKSPACE/sofia-sip"
|
||||
./ci.sh -t scan-build -a build -c sofia-sip -p "$GITHUB_WORKSPACE/sofia-sip"
|
||||
./ci.sh -t scan-build -a install -c sofia-sip -p "$GITHUB_WORKSPACE/sofia-sip"
|
||||
|
||||
+54
-15
@@ -1507,21 +1507,60 @@ PKG_CHECK_MODULES([MEMCACHED], [libmemcached >= 0.31],[
|
||||
AM_CONDITIONAL([HAVE_MEMCACHED],[false])
|
||||
])
|
||||
|
||||
PKG_CHECK_MODULES([V8FS_STATIC], [v8-6.1_static >= 6.1.298],[
|
||||
AM_CONDITIONAL([HAVE_V8FS],[true])],[
|
||||
PKG_CHECK_MODULES([V8FS_STATIC], [v8fs_static >= 6.1.298],[
|
||||
AM_CONDITIONAL([HAVE_V8FS],[true])],[
|
||||
PKG_CHECK_MODULES([V8FS_STATIC], [v8 >= 6.1.298],[
|
||||
AM_CONDITIONAL([HAVE_V8FS],[true])],[
|
||||
if module_enabled mod_v8; then
|
||||
AC_MSG_ERROR([You need to either install libv8-6.1-dev (>= 6.1.298), libv8fs-dev (>= 6.1.298) or disable mod_v8 in modules.conf])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
AM_CONDITIONAL([HAVE_V8FS],[false])
|
||||
fi
|
||||
])
|
||||
])
|
||||
])
|
||||
# mod_v8 needs the V8 JavaScript engine, provided by libnode-dev. It ships no
|
||||
# pkg-config file, so probe the well known header and library locations.
|
||||
AC_ARG_WITH([v8],
|
||||
[AS_HELP_STRING([--with-v8=DIR],
|
||||
[look for the libnode/V8 headers (the directory containing v8.h) in DIR])],
|
||||
[v8_incdir="$withval"], [v8_incdir=""])
|
||||
|
||||
have_v8="no"
|
||||
|
||||
AC_MSG_CHECKING([for libnode bundled V8 headers])
|
||||
V8_INCDIR=""
|
||||
for d in "$v8_incdir" /usr/include/nodejs/deps/v8/include /usr/include/node /usr/local/include/node /usr/include/v8 ; do
|
||||
if test -n "$d" && test -f "$d/v8.h" && test -f "$d/libplatform/libplatform.h" ; then
|
||||
V8_INCDIR="$d"; break
|
||||
fi
|
||||
done
|
||||
if test -n "$V8_INCDIR"; then
|
||||
AC_MSG_RESULT([$V8_INCDIR])
|
||||
AC_LANG_PUSH([C++])
|
||||
v8_save_LIBS="$LIBS"
|
||||
# Prefer the standalone split V8 libraries shipped by libnode-dev; fall
|
||||
# back to the all-in-one libnode if they are not present.
|
||||
AC_MSG_CHECKING([for standalone V8 libraries (-lv8 -lv8_libplatform)])
|
||||
LIBS="-lv8 -lv8_libplatform -lv8_libbase $v8_save_LIBS"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
|
||||
[AC_MSG_RESULT([yes]); V8_LIBS="-lv8 -lv8_libplatform -lv8_libbase"],
|
||||
[AC_MSG_RESULT([no])
|
||||
AC_MSG_CHECKING([for all-in-one libnode (-lnode)])
|
||||
LIBS="-lnode $v8_save_LIBS"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
|
||||
[AC_MSG_RESULT([yes]); V8_LIBS="-lnode"],
|
||||
[AC_MSG_RESULT([no])])])
|
||||
LIBS="$v8_save_LIBS"
|
||||
AC_LANG_POP([C++])
|
||||
if test -n "$V8_LIBS"; then
|
||||
V8_CFLAGS="-I$V8_INCDIR"
|
||||
have_v8="yes"
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
AC_SUBST([V8_CFLAGS])
|
||||
AC_SUBST([V8_LIBS])
|
||||
|
||||
if test "x$have_v8" = "xyes"; then
|
||||
AM_CONDITIONAL([HAVE_V8],[true])
|
||||
else
|
||||
if module_enabled mod_v8; then
|
||||
AC_MSG_ERROR([mod_v8 is enabled but libnode was not found. Install libnode-dev (Debian/Ubuntu: apt-get install libnode-dev) or disable mod_v8 in modules.conf])
|
||||
else
|
||||
AM_CONDITIONAL([HAVE_V8],[false])
|
||||
fi
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES([KS], [libks2 >= 2.0.11],[
|
||||
AM_CONDITIONAL([HAVE_KS],[true])],[
|
||||
|
||||
Vendored
-2
@@ -51,10 +51,8 @@ avoid_mods=(
|
||||
xml_int/mod_xml_ldap
|
||||
)
|
||||
avoid_mods_armhf=(
|
||||
languages/mod_v8
|
||||
)
|
||||
avoid_mods_arm64=(
|
||||
languages/mod_v8
|
||||
)
|
||||
avoid_mods_sid=(
|
||||
directories/mod_ldap
|
||||
|
||||
Vendored
+1
-1
@@ -540,7 +540,7 @@ Build-Depends-Trixie: python3-dev, python3-setuptools
|
||||
Module: languages/mod_v8
|
||||
Description: mod_v8
|
||||
Adds mod_v8.
|
||||
Build-Depends: git, libv8-6.1-dev
|
||||
Build-Depends: libnode-dev
|
||||
|
||||
## mod/loggers
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ AUTOMAKE_OPTIONS += foreign
|
||||
|
||||
MODNAME=mod_v8
|
||||
|
||||
AM_CFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8FS_STATIC_CFLAGS)
|
||||
AM_CPPFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8FS_STATIC_CFLAGS) -std=c++11
|
||||
AM_CFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8_CFLAGS)
|
||||
AM_CPPFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8_CFLAGS) -std=c++17
|
||||
AM_LDFLAGS += -avoid-version -module -no-undefined -shared
|
||||
|
||||
AM_LIBADD = $(switch_builddir)/libfreeswitch.la
|
||||
AM_LDFLAGS += $(V8FS_STATIC_LIBS)
|
||||
AM_LDFLAGS += $(V8_LIBS)
|
||||
|
||||
BUILT_SOURCES = $(V8LIB)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
/* Methods available from JavaScript */
|
||||
static void *Construct(const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
static v8::Handle<v8::Object> New(switch_dtmf_t *dtmf, const char *name, JSMain *js);
|
||||
static v8::Local<v8::Object> New(switch_dtmf_t *dtmf, const char *name, JSMain *js);
|
||||
JS_DTMF_GET_PROPERTY_DEF(GetProperty);
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
|
||||
/* Methods available from JavaScript */
|
||||
static void *Construct(const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
static v8::Handle<v8::Object> New(switch_event_t *event, const char *name, JSMain *js);
|
||||
static v8::Local<v8::Object> New(switch_event_t *event, const char *name, JSMain *js);
|
||||
JS_EVENT_FUNCTION_DEF(AddHeader);
|
||||
JS_EVENT_FUNCTION_DEF(GetHeader);
|
||||
JS_EVENT_FUNCTION_DEF(IsArrayHeader);
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
|
||||
void Init();
|
||||
void InitRootObject();
|
||||
v8::Handle<v8::Value> GetJSObjFromXMLObj(const switch_xml_t xml, const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
v8::Local<v8::Value> GetJSObjFromXMLObj(const switch_xml_t xml, const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
void StoreObjectInHash(switch_xml_t xml, FSXML *obj);
|
||||
FSXML *FindObjectInHash(switch_xml_t xml);
|
||||
void DeleteObjectInHash(switch_xml_t xml);
|
||||
|
||||
@@ -33,10 +33,160 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <v8.h>
|
||||
|
||||
/*
|
||||
* --- V8 API compatibility layer ---
|
||||
*
|
||||
* mod_v8 was originally written against the custom static V8 6.1 package. On
|
||||
* modern systems FreeSWITCH builds it against the V8 engine bundled with
|
||||
* upstream libnode-dev (V8 10.x). The two APIs differ in a handful of
|
||||
* mechanical but pervasive ways (MaybeLocal return values, mandatory Isolate*
|
||||
* / Context arguments, a few removed methods). The helpers below hide those
|
||||
* differences so the bulk of the module is shared between both engines.
|
||||
*
|
||||
* Windows keeps building against the old static V8 6.1, so the legacy (#else)
|
||||
* branches must remain valid. The active API is selected purely from
|
||||
* V8_MAJOR_VERSION, so no build-system define is required.
|
||||
*/
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 7
|
||||
#define V8FS_NEW_API 1
|
||||
#else
|
||||
#define V8FS_NEW_API 0
|
||||
#endif
|
||||
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5
|
||||
#include <libplatform/libplatform.h>
|
||||
#if !V8FS_NEW_API
|
||||
/* v8-util.h is unused by mod_v8 and is no longer shipped by libnode-dev. */
|
||||
#include <v8-util.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The isolate / context currently entered by the running script. mod_v8 only
|
||||
* touches V8 objects while a script is executing (inside an Isolate::Scope and
|
||||
* Context::Scope), where GetCurrent()/GetCurrentContext() are valid.
|
||||
*/
|
||||
static inline v8::Isolate *js_current_isolate(void)
|
||||
{
|
||||
return v8::Isolate::GetCurrent();
|
||||
}
|
||||
|
||||
static inline v8::Local<v8::Context> js_current_context(void)
|
||||
{
|
||||
return v8::Isolate::GetCurrent()->GetCurrentContext();
|
||||
}
|
||||
|
||||
/*
|
||||
* v8::String::NewFromUtf8() returns a Local on V8 6.1 but a MaybeLocal on
|
||||
* V8 7+. This wrapper always yields a Local<String> and tolerates a NULL str.
|
||||
*/
|
||||
static inline v8::Local<v8::String> js_new_string(v8::Isolate *isolate, const char *str, int length = -1)
|
||||
{
|
||||
#if V8FS_NEW_API
|
||||
return v8::String::NewFromUtf8(isolate, str ? str : "", v8::NewStringType::kNormal, length).ToLocalChecked();
|
||||
#else
|
||||
return v8::String::NewFromUtf8(isolate, str ? str : "", v8::String::kNormalString, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* v8::String::Utf8Value requires an explicit Isolate* on V8 7+. The single
|
||||
* argument constructor keeps the (very common) call sites unchanged by using
|
||||
* the currently entered isolate.
|
||||
*/
|
||||
class JsUtf8Value : public v8::String::Utf8Value
|
||||
{
|
||||
public:
|
||||
explicit JsUtf8Value(v8::Local<v8::Value> obj)
|
||||
#if V8FS_NEW_API
|
||||
: v8::String::Utf8Value(v8::Isolate::GetCurrent(), obj) {}
|
||||
#else
|
||||
: v8::String::Utf8Value(obj) {}
|
||||
#endif
|
||||
JsUtf8Value(v8::Isolate *isolate, v8::Local<v8::Value> obj)
|
||||
#if V8FS_NEW_API
|
||||
: v8::String::Utf8Value(isolate, obj) {}
|
||||
#else
|
||||
: v8::String::Utf8Value(obj) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
/* v8::Value::BooleanValue lost its no-argument form on V8 7+. */
|
||||
static inline bool js_to_bool(v8::Local<v8::Value> val)
|
||||
{
|
||||
#if V8FS_NEW_API
|
||||
return val->BooleanValue(v8::Isolate::GetCurrent());
|
||||
#else
|
||||
return val->BooleanValue();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* v8::Object::Set() / Get() lost their no-context forms on V8 7+. These run
|
||||
* while the script's context is entered, so the current context is used.
|
||||
*/
|
||||
static inline void js_obj_set(v8::Local<v8::Object> obj, v8::Local<v8::Value> key, v8::Local<v8::Value> val)
|
||||
{
|
||||
obj->Set(js_current_context(), key, val).FromMaybe(false);
|
||||
}
|
||||
|
||||
static inline v8::Local<v8::Value> js_obj_get(v8::Local<v8::Object> obj, v8::Local<v8::Value> key)
|
||||
{
|
||||
return obj->Get(js_current_context(), key).FromMaybe(v8::Local<v8::Value>());
|
||||
}
|
||||
|
||||
/*
|
||||
* v8::ReturnValue::Set() no longer accepts a Persistent handle on V8 7+;
|
||||
* convert it to a Local first. Local::New(isolate, persistent) is valid on the
|
||||
* old API too, so this helper works for both engines.
|
||||
*/
|
||||
template <typename T>
|
||||
static inline v8::Local<T> js_local(const v8::Persistent<T> &persistent)
|
||||
{
|
||||
return v8::Local<T>::New(v8::Isolate::GetCurrent(), persistent);
|
||||
}
|
||||
|
||||
/* v8::Script::Run() now requires a context and returns a MaybeLocal. */
|
||||
static inline v8::Local<v8::Value> js_run_script(v8::Local<v8::Script> script)
|
||||
{
|
||||
if (script.IsEmpty()) {
|
||||
return v8::Local<v8::Value>();
|
||||
}
|
||||
#if V8FS_NEW_API
|
||||
v8::Local<v8::Value> result;
|
||||
if (!script->Run(js_current_context()).ToLocal(&result)) {
|
||||
return v8::Local<v8::Value>();
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
return script->Run();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* v8::Function::Call now requires a context and returns a MaybeLocal. */
|
||||
static inline v8::Local<v8::Value> js_call(v8::Local<v8::Function> fn, v8::Local<v8::Value> recv, int argc, v8::Local<v8::Value> *argv)
|
||||
{
|
||||
#if V8FS_NEW_API
|
||||
v8::Local<v8::Value> result;
|
||||
if (!fn->Call(js_current_context(), recv, argc, argv).ToLocal(&result)) {
|
||||
return v8::Local<v8::Value>();
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
return fn->Call(recv, argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* v8::StackTrace::GetFrame() requires an Isolate* on V8 7+. */
|
||||
static inline v8::Local<v8::StackFrame> js_stack_frame(v8::Local<v8::StackTrace> trace, v8::Isolate *isolate, uint32_t index)
|
||||
{
|
||||
#if V8FS_NEW_API
|
||||
return trace->GetFrame(isolate, index);
|
||||
#else
|
||||
return trace->GetFrame(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -64,7 +214,7 @@
|
||||
} else {\
|
||||
int line;\
|
||||
char *file = JSMain::GetStackInfo(info.GetIsolate(), &line);\
|
||||
v8::String::Utf8Value str(info.Holder());\
|
||||
JsUtf8Value str(info.Holder());\
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "mod_v8", line, NULL, SWITCH_LOG_DEBUG, "No valid internal data available for %s when calling %s\n", *str ? *str : "[unknown]", #class_name "::" #method_name "()");\
|
||||
free(file);\
|
||||
info.GetReturnValue().Set(false);\
|
||||
@@ -83,10 +233,10 @@
|
||||
} else {\
|
||||
int line;\
|
||||
char *file = JSMain::GetStackInfo(info.GetIsolate(), &line);\
|
||||
v8::String::Utf8Value str(info.Holder());\
|
||||
JsUtf8Value str(info.Holder());\
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "mod_v8", line, NULL, SWITCH_LOG_DEBUG, "No valid internal data available for %s when calling %s\n", *str ? *str : "[unknown]", #class_name "::" #method_name "()");\
|
||||
free(file);\
|
||||
info.GetReturnValue().Set(false);\
|
||||
/* A property setter's ReturnValue is void; V8 7+ rejects Set() on it. */\
|
||||
}\
|
||||
}\
|
||||
void method_name##Impl(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
@@ -102,7 +252,7 @@
|
||||
} else {\
|
||||
int line;\
|
||||
char *file = JSMain::GetStackInfo(info.GetIsolate(), &line);\
|
||||
v8::String::Utf8Value str(info.Holder());\
|
||||
JsUtf8Value str(info.Holder());\
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "mod_v8", line, NULL, SWITCH_LOG_DEBUG, "No valid internal data available for %s when calling %s\n", *str ? *str : "[unknown]", #class_name "::" #method_name "()");\
|
||||
free(file);\
|
||||
info.GetReturnValue().Set(false);\
|
||||
@@ -226,14 +376,14 @@ private:
|
||||
static void CreateInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
|
||||
/* Store a C++ instance to a JS object's private data */
|
||||
static void AddInstance(v8::Isolate *isolate, const v8::Handle<v8::Object>& handle, const v8::Handle<v8::External>& object, bool autoDestroy);
|
||||
static void AddInstance(v8::Isolate *isolate, const v8::Local<v8::Object>& handle, const v8::Local<v8::External>& object, bool autoDestroy);
|
||||
public:
|
||||
JSBase(JSMain *owner);
|
||||
JSBase(const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
virtual ~JSBase(void);
|
||||
|
||||
/* Returns the JS object related to the C++ instance */
|
||||
v8::Handle<v8::Object> GetJavaScriptObject();
|
||||
v8::Local<v8::Object> GetJavaScriptObject();
|
||||
|
||||
/* Register a C++ class inside V8 (must be called within a entered isolate, and context) */
|
||||
static void Register(v8::Isolate *isolate, const js_class_definition_t *desc);
|
||||
@@ -263,7 +413,7 @@ public:
|
||||
}
|
||||
|
||||
/* Get a JavaScript function from a JavaScript argument (can be either a string or the actual function) */
|
||||
static v8::Handle<v8::Function> GetFunctionFromArg(v8::Isolate *isolate, const v8::Local<v8::Value>& arg);
|
||||
static v8::Local<v8::Function> GetFunctionFromArg(v8::Isolate *isolate, const v8::Local<v8::Value>& arg);
|
||||
|
||||
/* Default JS setter callback, to be used for read only values */
|
||||
static void DefaultSetProperty(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info);
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
#include "fseventhandler.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
using namespace v8;
|
||||
@@ -421,9 +422,9 @@ static int env_init(JSMain *js)
|
||||
static void v8_error(Isolate* isolate, TryCatch* try_catch)
|
||||
{
|
||||
HandleScope handle_scope(isolate);
|
||||
String::Utf8Value exception(try_catch->Exception());
|
||||
JsUtf8Value exception(try_catch->Exception());
|
||||
const char *exception_string = js_safe_str(*exception);
|
||||
Handle<Message> message = try_catch->Message();
|
||||
Local<Message> message = try_catch->Message();
|
||||
const char *msg;
|
||||
string filename = __FILE__;
|
||||
int line = __LINE__;
|
||||
@@ -437,16 +438,16 @@ static void v8_error(Isolate* isolate, TryCatch* try_catch)
|
||||
}
|
||||
|
||||
if (!message.IsEmpty()) {
|
||||
String::Utf8Value fname(message->GetScriptResourceName());
|
||||
JsUtf8Value fname(message->GetScriptResourceName());
|
||||
|
||||
if (*fname) {
|
||||
filename = *fname;
|
||||
}
|
||||
|
||||
line = message->GetLineNumber();
|
||||
line = message->GetLineNumber(js_current_context()).FromMaybe(0);
|
||||
msg = exception_string;
|
||||
|
||||
String::Utf8Value sourceline(message->GetSourceLine());
|
||||
JsUtf8Value sourceline(message->GetSourceLine(js_current_context()).ToLocalChecked());
|
||||
if (*sourceline) {
|
||||
text = *sourceline;
|
||||
}
|
||||
@@ -495,7 +496,7 @@ void perf_log(const char *fmt, ...)
|
||||
|
||||
switch_mutex_lock(globals.mutex);
|
||||
if (globals.performance_monitor) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, fmt, ap);
|
||||
switch_log_vprintf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, fmt, ap);
|
||||
}
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
|
||||
@@ -523,6 +524,7 @@ void LoadScript(MaybeLocal<v8::Script> *v8_script, Isolate *isolate, const char
|
||||
ScriptCompiler::CachedData *cached_data = 0;
|
||||
v8_compiled_script_cache_t *stored_compiled_script_cache = NULL;
|
||||
ScriptCompiler::CompileOptions options;
|
||||
bool produce_cache = false;
|
||||
|
||||
/*
|
||||
Do not cache if the caching is disabled
|
||||
@@ -557,30 +559,68 @@ void LoadScript(MaybeLocal<v8::Script> *v8_script, Isolate *isolate, const char
|
||||
|
||||
}
|
||||
|
||||
if (!cached_data) options = ScriptCompiler::kProduceCodeCache;
|
||||
if (!cached_data) {
|
||||
#if V8FS_NEW_API
|
||||
/* V8 7+ removed kProduceCodeCache; the code cache is created
|
||||
* explicitly from the compiled script further down. */
|
||||
options = ScriptCompiler::kNoCompileOptions;
|
||||
#else
|
||||
options = ScriptCompiler::kProduceCodeCache;
|
||||
#endif
|
||||
produce_cache = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ScriptCompiler::Source source(String::NewFromUtf8(isolate, script_data), cached_data);
|
||||
ScriptCompiler::Source source(js_new_string(isolate, script_data), cached_data);
|
||||
*v8_script = ScriptCompiler::Compile(isolate->GetCurrentContext(), &source, options);
|
||||
|
||||
if (!v8_script->IsEmpty()) {
|
||||
|
||||
if (options == ScriptCompiler::kProduceCodeCache && !source.GetCachedData()->rejected) {
|
||||
int length = source.GetCachedData()->length;
|
||||
uint8_t* raw_cached_data = new uint8_t[length];
|
||||
v8_compiled_script_cache_t *compiled_script_cache = new v8_compiled_script_cache_t;
|
||||
memcpy(raw_cached_data, source.GetCachedData()->data, static_cast<size_t>(length));
|
||||
compiled_script_cache->data.reset(raw_cached_data, array_deleter<uint8_t>());
|
||||
compiled_script_cache->length = length;
|
||||
compiled_script_cache->compile_time = switch_time_now();
|
||||
if (produce_cache) {
|
||||
#if V8FS_NEW_API
|
||||
/* Produce the code cache explicitly from the freshly compiled script. */
|
||||
Local<v8::Script> compiled_script;
|
||||
ScriptCompiler::CachedData *produced = NULL;
|
||||
|
||||
switch_mutex_lock(globals.compiled_script_hash_mutex);
|
||||
switch_core_hash_insert_destructor(globals.compiled_script_hash, script_file, compiled_script_cache, destructor);
|
||||
switch_mutex_unlock(globals.compiled_script_hash_mutex);
|
||||
if (v8_script->ToLocal(&compiled_script)) {
|
||||
produced = ScriptCompiler::CreateCodeCache(compiled_script->GetUnboundScript());
|
||||
}
|
||||
|
||||
perf_log("Javascript ['%s'] cache was produced.\n", script_file);
|
||||
if (produced) {
|
||||
int length = produced->length;
|
||||
uint8_t* raw_cached_data = new uint8_t[length];
|
||||
v8_compiled_script_cache_t *compiled_script_cache = new v8_compiled_script_cache_t;
|
||||
memcpy(raw_cached_data, produced->data, static_cast<size_t>(length));
|
||||
compiled_script_cache->data.reset(raw_cached_data, array_deleter<uint8_t>());
|
||||
compiled_script_cache->length = length;
|
||||
compiled_script_cache->compile_time = switch_time_now();
|
||||
|
||||
switch_mutex_lock(globals.compiled_script_hash_mutex);
|
||||
switch_core_hash_insert_destructor(globals.compiled_script_hash, script_file, compiled_script_cache, destructor);
|
||||
switch_mutex_unlock(globals.compiled_script_hash_mutex);
|
||||
|
||||
perf_log("Javascript ['%s'] cache was produced.\n", script_file);
|
||||
|
||||
delete produced;
|
||||
}
|
||||
#else
|
||||
if (!source.GetCachedData()->rejected) {
|
||||
int length = source.GetCachedData()->length;
|
||||
uint8_t* raw_cached_data = new uint8_t[length];
|
||||
v8_compiled_script_cache_t *compiled_script_cache = new v8_compiled_script_cache_t;
|
||||
memcpy(raw_cached_data, source.GetCachedData()->data, static_cast<size_t>(length));
|
||||
compiled_script_cache->data.reset(raw_cached_data, array_deleter<uint8_t>());
|
||||
compiled_script_cache->length = length;
|
||||
compiled_script_cache->compile_time = switch_time_now();
|
||||
|
||||
switch_mutex_lock(globals.compiled_script_hash_mutex);
|
||||
switch_core_hash_insert_destructor(globals.compiled_script_hash, script_file, compiled_script_cache, destructor);
|
||||
switch_mutex_unlock(globals.compiled_script_hash_mutex);
|
||||
|
||||
perf_log("Javascript ['%s'] cache was produced.\n", script_file);
|
||||
}
|
||||
#endif
|
||||
} else if (options == ScriptCompiler::kConsumeCodeCache) {
|
||||
|
||||
if (source.GetCachedData()->rejected) {
|
||||
@@ -665,7 +705,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
switch_mutex_unlock(globals.task_manager_mutex);
|
||||
|
||||
// New global template
|
||||
Handle<ObjectTemplate> global = ObjectTemplate::New(isolate);
|
||||
Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
|
||||
|
||||
if (global.IsEmpty()) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create JS global object template\n");
|
||||
@@ -673,7 +713,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
/* Add all global functions */
|
||||
for (size_t i = 0; i < js->GetExtenderFunctions().size(); i++) {
|
||||
js_function_t *proc = js->GetExtenderFunctions()[i];
|
||||
global->Set(String::NewFromUtf8(isolate, proc->name), FunctionTemplate::New(isolate, proc->func));
|
||||
global->Set(js_new_string(isolate, proc->name), FunctionTemplate::New(isolate, proc->func));
|
||||
}
|
||||
|
||||
// Create a new context.
|
||||
@@ -721,7 +761,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
obj->RegisterInstance(isolate, "session", true);
|
||||
} else {
|
||||
/* Add a session object as a boolean instead, just to make it safe to check if it exists as expected */
|
||||
context->Global()->Set(String::NewFromUtf8(isolate, "session"), Boolean::New(isolate, false));
|
||||
js_obj_set(context->Global(), js_new_string(isolate, "session"), Boolean::New(isolate, false));
|
||||
}
|
||||
|
||||
if (v8_event) {
|
||||
@@ -742,14 +782,14 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
{
|
||||
/* Add xml handler global variables */
|
||||
|
||||
Handle<Array> XML_REQUEST = Array::New(isolate, 4);
|
||||
Local<Array> XML_REQUEST = Array::New(isolate, 4);
|
||||
|
||||
XML_REQUEST->Set(String::NewFromUtf8(isolate, "key_name"), String::NewFromUtf8(isolate, js_safe_str(xml_handler->key_name)));
|
||||
XML_REQUEST->Set(String::NewFromUtf8(isolate, "key_value"), String::NewFromUtf8(isolate, js_safe_str(xml_handler->key_value)));
|
||||
XML_REQUEST->Set(String::NewFromUtf8(isolate, "section"), String::NewFromUtf8(isolate, js_safe_str(xml_handler->section)));
|
||||
XML_REQUEST->Set(String::NewFromUtf8(isolate, "tag_name"), String::NewFromUtf8(isolate, js_safe_str(xml_handler->tag_name)));
|
||||
js_obj_set(XML_REQUEST, js_new_string(isolate, "key_name"), js_new_string(isolate, js_safe_str(xml_handler->key_name)));
|
||||
js_obj_set(XML_REQUEST, js_new_string(isolate, "key_value"), js_new_string(isolate, js_safe_str(xml_handler->key_value)));
|
||||
js_obj_set(XML_REQUEST, js_new_string(isolate, "section"), js_new_string(isolate, js_safe_str(xml_handler->section)));
|
||||
js_obj_set(XML_REQUEST, js_new_string(isolate, "tag_name"), js_new_string(isolate, js_safe_str(xml_handler->tag_name)));
|
||||
|
||||
context->Global()->Set(String::NewFromUtf8(isolate, "XML_REQUEST"), XML_REQUEST);
|
||||
js_obj_set(context->Global(), js_new_string(isolate, "XML_REQUEST"), XML_REQUEST);
|
||||
|
||||
if (xml_handler->params) {
|
||||
FSEvent::New(xml_handler->params, "params", js);
|
||||
@@ -767,10 +807,10 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
// Add arguments before running script.
|
||||
Local<Array> arguments = Array::New(isolate, argc);
|
||||
for (int y = 0; y < argc; y++) {
|
||||
arguments->Set(Integer::New(isolate, y), String::NewFromUtf8(isolate, argv[y]));
|
||||
js_obj_set(arguments, Integer::New(isolate, y), js_new_string(isolate, argv[y]));
|
||||
}
|
||||
context->Global()->Set(String::NewFromUtf8(isolate, "argv"), arguments);
|
||||
context->Global()->Set(String::NewFromUtf8(isolate, "argc"), Integer::New(isolate, argc));
|
||||
js_obj_set(context->Global(), js_new_string(isolate, "argv"), arguments);
|
||||
js_obj_set(context->Global(), js_new_string(isolate, "argc"), Integer::New(isolate, argc));
|
||||
}
|
||||
|
||||
const char *script_data = NULL;
|
||||
@@ -806,7 +846,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
/* Store our base directory in variable 'scriptPath' */
|
||||
char *scriptPath = v8_get_script_path(script_file);
|
||||
if (scriptPath) {
|
||||
context->Global()->Set(String::NewFromUtf8(isolate, "scriptPath"), String::NewFromUtf8(isolate, scriptPath));
|
||||
js_obj_set(context->Global(), js_new_string(isolate, "scriptPath"), js_new_string(isolate, scriptPath));
|
||||
switch_safe_free(scriptPath);
|
||||
}
|
||||
|
||||
@@ -819,8 +859,8 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
LoadScript(&v8_script, isolate, script_data, script_file);
|
||||
#else
|
||||
// Create a string containing the JavaScript source code.
|
||||
Handle<String> source = String::NewFromUtf8(isolate, script_data);
|
||||
Handle<Script> v8_script = Script::Compile(source, Local<Value>::New(isolate, String::NewFromUtf8(isolate, script_file)));
|
||||
Local<String> source = js_new_string(isolate, script_data);
|
||||
Local<Script> v8_script = Script::Compile(source, Local<Value>::New(isolate, js_new_string(isolate, script_file)));
|
||||
#endif
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
@@ -835,10 +875,10 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
#endif
|
||||
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5
|
||||
Handle<Value> script_result;
|
||||
Local<Value> script_result;
|
||||
|
||||
if (!v8_script.IsEmpty()) {
|
||||
script_result = v8_script.ToLocalChecked()->Run();
|
||||
script_result = js_run_script(v8_script.ToLocalChecked());
|
||||
}
|
||||
|
||||
switch_mutex_lock(globals.mutex);
|
||||
@@ -849,7 +889,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
}
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
#else
|
||||
Handle<Value> result = v8_script->Run();
|
||||
Local<Value> result = js_run_script(v8_script);
|
||||
#endif
|
||||
if (try_catch.HasCaught()) {
|
||||
v8_error(isolate, &try_catch);
|
||||
@@ -861,7 +901,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
|
||||
if (!script_result.IsEmpty()) {
|
||||
// Return result as string
|
||||
String::Utf8Value ascii(script_result);
|
||||
JsUtf8Value ascii(script_result);
|
||||
if (*ascii) {
|
||||
res = *ascii;
|
||||
}
|
||||
@@ -869,8 +909,8 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
|
||||
|
||||
if (xml_handler)
|
||||
{
|
||||
Local<Value> value = context->Global()->Get(String::NewFromUtf8(isolate, "XML_STRING"));
|
||||
String::Utf8Value str(value);
|
||||
Local<Value> value = js_obj_get(context->Global(), js_new_string(isolate, "XML_STRING"));
|
||||
JsUtf8Value str(value);
|
||||
if (strcmp(js_safe_str(*str), "undefined"))
|
||||
{
|
||||
xml_handler->XML_STRING = strdup(js_safe_str(*str));
|
||||
|
||||
@@ -95,11 +95,11 @@ void *FSSkel::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
/* Parse input variables */
|
||||
if (info.Length() > 0) {
|
||||
if (!info[0].IsEmpty() && info[0]->IsInt32()) {
|
||||
obj->x = info[0]->Int32Value();
|
||||
obj->x = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (!info[1].IsEmpty() && info[1]->IsString()) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
if (*str) {
|
||||
obj->y = *str;
|
||||
}
|
||||
@@ -117,19 +117,19 @@ JS_SKEL_GET_PROPERTY_IMPL(GetPropertyX)
|
||||
|
||||
JS_SKEL_SET_PROPERTY_IMPL(SetPropertyX)
|
||||
{
|
||||
x = value->Int32Value();
|
||||
x = value->Int32Value(js_current_context()).FromMaybe(0);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FSSkel::SetPropertyX to %d\n", x);
|
||||
}
|
||||
|
||||
JS_SKEL_GET_PROPERTY_IMPL(GetPropertyY)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FSSkel::GetPropertyY (%s)\n", y.c_str());
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), y.c_str()));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), y.c_str()));
|
||||
}
|
||||
|
||||
JS_SKEL_SET_PROPERTY_IMPL(SetPropertyY)
|
||||
{
|
||||
String::Utf8Value str(value);
|
||||
JsUtf8Value str(value);
|
||||
|
||||
y = js_safe_str(*str);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FSSkel::SetPropertyY to '%s'\n", y.c_str());
|
||||
@@ -138,7 +138,7 @@ JS_SKEL_SET_PROPERTY_IMPL(SetPropertyY)
|
||||
JS_SKEL_GET_PROPERTY_IMPL(GetPropertyZ)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FSSkel::GetPropertyZ (z)\n");
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), "z"));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), "z"));
|
||||
}
|
||||
|
||||
JS_SKEL_FUNCTION_IMPL(MyFunction)
|
||||
@@ -149,7 +149,7 @@ JS_SKEL_FUNCTION_IMPL(MyFunction)
|
||||
JS_SKEL_FUNCTION_IMPL(MyFunction2)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FSSkel::MyFunction2 - will twrow a JavaScript exception\n");
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Error in MyFunction2()"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Error in MyFunction2()"));
|
||||
}
|
||||
|
||||
/* Add the JS methods here */
|
||||
|
||||
@@ -75,14 +75,14 @@ void *FSCoreDB::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
switch_core_db_t *db;
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *dbname = js_safe_str(*str);
|
||||
|
||||
switch_core_new_memory_pool(&pool);
|
||||
|
||||
if (!(db = switch_core_db_open_file(dbname))) {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot Open DB!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot Open DB!"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ void *FSCoreDB::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
return dbo;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -110,23 +110,23 @@ int FSCoreDB::Callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
HandleScope handle_scope(dbo->GetIsolate());
|
||||
|
||||
if (dbo->_callback.IsEmpty()) {
|
||||
dbo->GetIsolate()->ThrowException(String::NewFromUtf8(dbo->GetIsolate(), "No callback specified"));
|
||||
dbo->GetIsolate()->ThrowException(js_new_string(dbo->GetIsolate(), "No callback specified"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Handle<Array> arg = Array::New(dbo->GetIsolate(), argc);
|
||||
Local<Array> arg = Array::New(dbo->GetIsolate(), argc);
|
||||
|
||||
for (x = 0; x < argc; x++) {
|
||||
if (columnNames[x] && argv[x]) {
|
||||
arg->Set(String::NewFromUtf8(dbo->GetIsolate(), columnNames[x]), String::NewFromUtf8(dbo->GetIsolate(), argv[x]));
|
||||
js_obj_set(arg, js_new_string(dbo->GetIsolate(), columnNames[x]), js_new_string(dbo->GetIsolate(), argv[x]));
|
||||
}
|
||||
}
|
||||
|
||||
HandleScope scope(dbo->GetIsolate());
|
||||
Handle<Function> func = Local<Function>::New(dbo->GetIsolate(), dbo->_callback);
|
||||
Handle<Value> jsargv[1] = { arg };
|
||||
Local<Function> func = Local<Function>::New(dbo->GetIsolate(), dbo->_callback);
|
||||
Local<Value> jsargv[1] = { arg };
|
||||
|
||||
func->Call(dbo->GetIsolate()->GetCurrentContext()->Global(), 1, jsargv);
|
||||
js_call(func, dbo->GetIsolate()->GetCurrentContext()->Global(), 1, jsargv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -143,19 +143,19 @@ JS_COREDB_FUNCTION_IMPL(Exec)
|
||||
info.GetReturnValue().Set(0);
|
||||
|
||||
if (!_db) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *sql = js_safe_str(*str);
|
||||
char *err = NULL;
|
||||
void *arg = NULL;
|
||||
switch_core_db_callback_func_t cb_func = NULL;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
if (!func.IsEmpty()) {
|
||||
_callback.Reset(info.GetIsolate(), func);
|
||||
cb_func = FSCoreDB::Callback;
|
||||
@@ -189,7 +189,7 @@ void FSCoreDB::StepEx(const v8::FunctionCallbackInfo<Value>& info, int stepSucce
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (!_db) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,24 +247,24 @@ JS_COREDB_FUNCTION_IMPL(Fetch)
|
||||
int x;
|
||||
|
||||
if (!_db) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_stmt) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "No query is active"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "No query is active"));
|
||||
return;
|
||||
}
|
||||
|
||||
colcount = switch_core_db_column_count(_stmt);
|
||||
Handle<Array> arg = Array::New(info.GetIsolate(), colcount);
|
||||
Local<Array> arg = Array::New(info.GetIsolate(), colcount);
|
||||
|
||||
for (x = 0; x < colcount; x++) {
|
||||
const char *var = (char *) switch_core_db_column_name(_stmt, x);
|
||||
const char *val = (char *) switch_core_db_column_text(_stmt, x);
|
||||
|
||||
if (var && val) {
|
||||
arg->Set(String::NewFromUtf8(info.GetIsolate(), var), String::NewFromUtf8(info.GetIsolate(), val));
|
||||
js_obj_set(arg, js_new_string(info.GetIsolate(), var), js_new_string(info.GetIsolate(), val));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ JS_COREDB_FUNCTION_IMPL(Prepare)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (!_db) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ JS_COREDB_FUNCTION_IMPL(Prepare)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *sql = js_safe_str(*str);
|
||||
if (switch_core_db_prepare(_db, sql, -1, &_stmt, 0)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(_db));
|
||||
@@ -307,34 +307,34 @@ JS_COREDB_FUNCTION_IMPL(BindText)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (!_db) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* db_prepare() must be called first */
|
||||
if (!_stmt) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "prepare() must be called first"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "prepare() must be called first"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() < 2) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* convert args */
|
||||
param_index = info[0]->Int32Value();
|
||||
String::Utf8Value str(info[1]);
|
||||
param_index = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
JsUtf8Value str(info[1]);
|
||||
param_value = js_safe_str(*str);
|
||||
if ((param_index < 1) || (param_value.length() == 0)) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* bind param */
|
||||
if (switch_core_db_bind_text(_stmt, param_index, param_value.c_str(), -1, SWITCH_CORE_DB_TRANSIENT)) {
|
||||
char *err = switch_mprintf("Database error %s", switch_core_db_errmsg(_db));
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return;
|
||||
} else {
|
||||
@@ -351,34 +351,34 @@ JS_COREDB_FUNCTION_IMPL(BindInt)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (!_db) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* db_prepare() must be called first */
|
||||
if (!_stmt) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "prepare() must be called first"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "prepare() must be called first"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() < 2) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* convert args */
|
||||
param_index = info[0]->Int32Value();
|
||||
param_value = info[1]->Int32Value();
|
||||
param_index = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
param_value = info[1]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
|
||||
if (param_index < 1) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* bind param */
|
||||
if (switch_core_db_bind_int(_stmt, param_index, param_value)) {
|
||||
char *err = switch_mprintf("Database error %s", switch_core_db_errmsg(_db));
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return;
|
||||
} else {
|
||||
@@ -390,16 +390,16 @@ JS_COREDB_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!strcmp(js_safe_str(*str), "path")) {
|
||||
if (_dbname) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), _dbname));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), _dbname));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,14 +62,14 @@ size_t FSCURL::FileCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
FSCURL *obj = static_cast<FSCURL *>(data);
|
||||
unsigned int realsize = (unsigned int) (size * nmemb);
|
||||
uint32_t argc = 0;
|
||||
Handle<Value> argv[4];
|
||||
Local<Value> argv[4];
|
||||
|
||||
if (!obj) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HandleScope handle_scope(obj->GetIsolate());
|
||||
Handle<Function> func;
|
||||
Local<Function> func;
|
||||
|
||||
if (!obj->_function.IsEmpty()) {
|
||||
func = Local<Function>::New(obj->GetIsolate(), obj->_function);
|
||||
@@ -78,15 +78,15 @@ size_t FSCURL::FileCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
if (!func.IsEmpty()) {
|
||||
char *ret;
|
||||
if (ptr) {
|
||||
argv[argc++] = String::NewFromUtf8(obj->GetIsolate(), (char *)ptr);
|
||||
argv[argc++] = js_new_string(obj->GetIsolate(), (char *)ptr);
|
||||
} else {
|
||||
argv[argc++] = String::NewFromUtf8(obj->GetIsolate(), "");
|
||||
argv[argc++] = js_new_string(obj->GetIsolate(), "");
|
||||
}
|
||||
if (!obj->_user_data.IsEmpty()) {
|
||||
argv[argc++] = Local<Value>::New(obj->GetIsolate(), Persistent<Value>::Cast(obj->_user_data));
|
||||
}
|
||||
|
||||
Handle<Value> res = func->Call(obj->GetIsolate()->GetCurrentContext()->Global(), argc, argv);
|
||||
Local<Value> res = js_call(func, obj->GetIsolate()->GetCurrentContext()->Global(), argc, argv);
|
||||
|
||||
if (!res.IsEmpty()){
|
||||
obj->_ret.Reset(obj->GetIsolate(), res);
|
||||
@@ -94,7 +94,7 @@ size_t FSCURL::FileCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
obj->_ret.Reset();
|
||||
}
|
||||
|
||||
String::Utf8Value str(Local<Value>::New(obj->GetIsolate(), res));
|
||||
JsUtf8Value str(Local<Value>::New(obj->GetIsolate(), res));
|
||||
|
||||
if ((ret = *str)) {
|
||||
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
|
||||
@@ -129,12 +129,12 @@ JS_CURL_FUNCTION_IMPL(Run)
|
||||
char ct[80] = "Content-Type: application/x-www-form-urlencoded";
|
||||
|
||||
if (info.Length() < 2) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
|
||||
method = js_safe_str(*str1);
|
||||
url = js_safe_str(*str2);
|
||||
@@ -146,23 +146,23 @@ JS_CURL_FUNCTION_IMPL(Run)
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
String::Utf8Value str3(info[2]);
|
||||
JsUtf8Value str3(info[2]);
|
||||
data = js_safe_str(*str3);
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[3]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[3]);
|
||||
if (!func.IsEmpty() && func->IsFunction()) {
|
||||
_function.Reset(info.GetIsolate(), func);
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Length() > 4) {
|
||||
_user_data.Reset(info.GetIsolate(), Handle<Object>::Cast(info[4]));
|
||||
_user_data.Reset(info.GetIsolate(), Local<Object>::Cast(info[4]));
|
||||
}
|
||||
|
||||
if (info.Length() > 5) {
|
||||
String::Utf8Value str4(info[5]);
|
||||
JsUtf8Value str4(info[5]);
|
||||
cred = js_safe_str(*str4);
|
||||
if (cred.length() > 0) {
|
||||
switch_curl_easy_setopt(_curl_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
|
||||
@@ -171,14 +171,14 @@ JS_CURL_FUNCTION_IMPL(Run)
|
||||
}
|
||||
|
||||
if (info.Length() > 6) {
|
||||
timeout = info[6]->Int32Value();
|
||||
timeout = info[6]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
if (timeout > 0) {
|
||||
switch_curl_easy_setopt(_curl_handle, CURLOPT_TIMEOUT, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Length() > 7) {
|
||||
String::Utf8Value str5(info[7]);
|
||||
JsUtf8Value str5(info[7]);
|
||||
const char *content_type = js_safe_str(*str5);
|
||||
switch_snprintf(ct, sizeof(ct), "Content-Type: %s", content_type);
|
||||
}
|
||||
@@ -221,7 +221,7 @@ JS_CURL_FUNCTION_IMPL(Run)
|
||||
switch_safe_free(durl);
|
||||
|
||||
if (!_ret.IsEmpty()) {
|
||||
info.GetReturnValue().Set(_ret);
|
||||
info.GetReturnValue().Set(js_local(_ret));
|
||||
_ret.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,22 +113,22 @@ void *FSDBH::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
char *dsn, *username = NULL, *password = NULL;
|
||||
|
||||
if (info.Length() < 1 || info.Length() > 3) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid parameters"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid parameters"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String::Utf8Value str1(info[0]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
dsn = *str1;
|
||||
|
||||
if (info.Length() > 1)
|
||||
{
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
username = *str2;
|
||||
}
|
||||
|
||||
if (info.Length() > 2)
|
||||
{
|
||||
String::Utf8Value str3(info[2]);
|
||||
JsUtf8Value str3(info[2]);
|
||||
password = *str3;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ void *FSDBH::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
}
|
||||
|
||||
if (!dbh_obj) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to create new DBH instance"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to create new DBH instance"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -164,23 +164,23 @@ int FSDBH::Callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
HandleScope handle_scope(dbo->GetIsolate());
|
||||
|
||||
if (dbo->_callback.IsEmpty()) {
|
||||
dbo->GetIsolate()->ThrowException(String::NewFromUtf8(dbo->GetIsolate(), "No callback specified"));
|
||||
dbo->GetIsolate()->ThrowException(js_new_string(dbo->GetIsolate(), "No callback specified"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Handle<Array> arg = Array::New(dbo->GetIsolate(), argc);
|
||||
Local<Array> arg = Array::New(dbo->GetIsolate(), argc);
|
||||
|
||||
for (x = 0; x < argc; x++) {
|
||||
if (columnNames[x] && argv[x]) {
|
||||
arg->Set(String::NewFromUtf8(dbo->GetIsolate(), columnNames[x]), String::NewFromUtf8(dbo->GetIsolate(), argv[x]));
|
||||
js_obj_set(arg, js_new_string(dbo->GetIsolate(), columnNames[x]), js_new_string(dbo->GetIsolate(), argv[x]));
|
||||
}
|
||||
}
|
||||
|
||||
HandleScope scope(dbo->GetIsolate());
|
||||
Handle<Function> func = Local<Function>::New(dbo->GetIsolate(), dbo->_callback);
|
||||
Handle<Value> jsargv[1] = { arg };
|
||||
Local<Function> func = Local<Function>::New(dbo->GetIsolate(), dbo->_callback);
|
||||
Local<Value> jsargv[1] = { arg };
|
||||
|
||||
func->Call(dbo->GetIsolate()->GetCurrentContext()->Global(), 1, jsargv);
|
||||
js_call(func, dbo->GetIsolate()->GetCurrentContext()->Global(), 1, jsargv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -193,9 +193,9 @@ void FSDBH::clear_error()
|
||||
JS_DBH_FUNCTION_IMPL(last_error)
|
||||
{
|
||||
if (err)
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), err));
|
||||
else
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -208,16 +208,16 @@ JS_DBH_FUNCTION_IMPL(query)
|
||||
clear_error();
|
||||
|
||||
if (info.Length() < 1 || info.Length() > 2) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid parameters"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid parameters"));
|
||||
return info.GetReturnValue().Set(false);
|
||||
}
|
||||
|
||||
if (!dbh) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return info.GetReturnValue().Set(false);
|
||||
}
|
||||
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *sql = js_safe_str(*str);
|
||||
|
||||
if (zstr(sql)) {
|
||||
@@ -228,7 +228,7 @@ JS_DBH_FUNCTION_IMPL(query)
|
||||
void *arg = NULL;
|
||||
switch_core_db_callback_func_t cb_func = NULL;
|
||||
|
||||
Handle<Function> func = Handle<Function>();
|
||||
Local<Function> func = Local<Function>();
|
||||
|
||||
if (info.Length() > 1)
|
||||
func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
@@ -282,18 +282,18 @@ JS_DBH_FUNCTION_IMPL(test_reactive)
|
||||
clear_error();
|
||||
|
||||
if (info.Length() < 3) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid parameters"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid parameters"));
|
||||
return info.GetReturnValue().Set(false);
|
||||
}
|
||||
|
||||
if (!dbh) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Database is not connected"));
|
||||
return info.GetReturnValue().Set(false);
|
||||
}
|
||||
|
||||
String::Utf8Value str0(info[0]);
|
||||
String::Utf8Value str1(info[1]);
|
||||
String::Utf8Value str2(info[2]);
|
||||
JsUtf8Value str0(info[0]);
|
||||
JsUtf8Value str1(info[1]);
|
||||
JsUtf8Value str2(info[2]);
|
||||
const char *test_sql = js_safe_str(*str0);
|
||||
const char *drop_sql = js_safe_str(*str1);
|
||||
const char *reactive_sql = js_safe_str(*str2);
|
||||
@@ -335,13 +335,13 @@ JS_DBH_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!strcmp(js_safe_str(*str), "dsn")) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), _dsn.c_str()));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), _dsn.c_str()));
|
||||
}
|
||||
else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ string FSDTMF::GetJSClassName()
|
||||
return js_class_name;
|
||||
}
|
||||
|
||||
Handle<Object> FSDTMF::New(switch_dtmf_t *dtmf, const char *name, JSMain *js)
|
||||
Local<Object> FSDTMF::New(switch_dtmf_t *dtmf, const char *name, JSMain *js)
|
||||
{
|
||||
FSDTMF *obj;
|
||||
switch_dtmf_t *ddtmf;
|
||||
@@ -63,7 +63,7 @@ Handle<Object> FSDTMF::New(switch_dtmf_t *dtmf, const char *name, JSMain *js)
|
||||
}
|
||||
}
|
||||
|
||||
return Handle<Object>();
|
||||
return Local<Object>();
|
||||
}
|
||||
|
||||
void *FSDTMF::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
@@ -74,15 +74,15 @@ void *FSDTMF::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
const char *dtmf_char;
|
||||
|
||||
if (info.Length() <= 0) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid Args"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid Args"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
dtmf_char = *str;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
duration = info[1]->Int32Value();
|
||||
duration = info[1]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
if (duration <= 0) {
|
||||
duration = switch_core_default_dtmf_duration(0);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ void *FSDTMF::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
return obj;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Memory error"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Memory error"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -115,16 +115,16 @@ JS_DTMF_GET_PROPERTY_IMPL(GetProperty)
|
||||
return;
|
||||
}
|
||||
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
const char *prop = js_safe_str(*str);
|
||||
|
||||
if (!strcmp(prop, "digit")) {
|
||||
char tmp[2] = { obj->_dtmf->digit, '\0' };
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), tmp));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), tmp));
|
||||
} else if (!strcmp(prop, "duration")) {
|
||||
info.GetReturnValue().Set(Integer::New(info.GetIsolate(), obj->_dtmf->duration));
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ switch_event_t **FSEvent::GetEvent()
|
||||
return &_event;
|
||||
}
|
||||
|
||||
Handle<Object> FSEvent::New(switch_event_t *event, const char *name, JSMain *js)
|
||||
Local<Object> FSEvent::New(switch_event_t *event, const char *name, JSMain *js)
|
||||
{
|
||||
FSEvent *obj;
|
||||
|
||||
@@ -98,7 +98,7 @@ Handle<Object> FSEvent::New(switch_event_t *event, const char *name, JSMain *js)
|
||||
return obj->GetJavaScriptObject();
|
||||
}
|
||||
|
||||
return Handle<Object>();
|
||||
return Local<Object>();
|
||||
}
|
||||
|
||||
void *FSEvent::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
@@ -109,13 +109,13 @@ void *FSEvent::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
switch_event_t *event;
|
||||
FSEvent *obj;
|
||||
switch_event_types_t etype;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *ename = js_safe_str(*str);
|
||||
|
||||
if ((obj = new FSEvent(info))) {
|
||||
if (switch_name_event(ename, &etype) != SWITCH_STATUS_SUCCESS) {
|
||||
char *err = switch_mprintf("Unknown event %s", ename);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
delete obj;
|
||||
return NULL;
|
||||
@@ -124,7 +124,7 @@ void *FSEvent::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
if (etype == SWITCH_EVENT_CUSTOM) {
|
||||
string subclass_name;
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
if (*str2) {
|
||||
subclass_name = js_safe_str(*str2);
|
||||
}
|
||||
@@ -133,20 +133,20 @@ void *FSEvent::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
}
|
||||
|
||||
if (switch_event_create_subclass(&event, etype, subclass_name.c_str()) != SWITCH_STATUS_SUCCESS) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to create sub class"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to create sub class"));
|
||||
delete obj;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (switch_event_create(&event, etype) != SWITCH_STATUS_SUCCESS) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to create event"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to create event"));
|
||||
delete obj;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Third argument tells if the headers should be unique */
|
||||
if (event && !info[2].IsEmpty() && info[2]->BooleanValue()) {
|
||||
if (event && !info[2].IsEmpty() && js_to_bool(info[2])) {
|
||||
event->flags |= EF_UNIQ_HEADERS;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ void *FSEvent::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
}
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid Args"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid Args"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -171,14 +171,14 @@ JS_EVENT_FUNCTION_IMPL(AddHeader)
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
const char *hname = js_safe_str(*str1);
|
||||
const char *hval = js_safe_str(*str2);
|
||||
switch_stack_t stack_kind = SWITCH_STACK_BOTTOM;
|
||||
|
||||
/* Check if we should push this value to the end of an array */
|
||||
if (!info[2].IsEmpty() && info[2]->BooleanValue()) {
|
||||
if (!info[2].IsEmpty() && js_to_bool(info[2])) {
|
||||
stack_kind = SWITCH_STACK_PUSH;
|
||||
}
|
||||
|
||||
@@ -200,14 +200,14 @@ JS_EVENT_FUNCTION_IMPL(GetHeader)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *hname = js_safe_str(*str);
|
||||
const char *val = NULL;
|
||||
int idx = -1;
|
||||
|
||||
/* Check if caller expects to get data from an array */
|
||||
if (info.Length() > 1 && !info[1].IsEmpty()) {
|
||||
idx = info[1]->Int32Value();
|
||||
idx = info[1]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
|
||||
if (idx < 0 || !IsArray(hname)) {
|
||||
idx = -1;
|
||||
@@ -224,7 +224,7 @@ JS_EVENT_FUNCTION_IMPL(GetHeader)
|
||||
/* Return null if we fetched and array value that didn't exist (so we know when to exit a loop) */
|
||||
info.GetReturnValue().Set(Null(info.GetIsolate()));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(val)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(val)));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -241,7 +241,7 @@ JS_EVENT_FUNCTION_IMPL(IsArrayHeader)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
info.GetReturnValue().Set(IsArray(js_safe_str(*str)));
|
||||
} else {
|
||||
info.GetReturnValue().Set(false);
|
||||
@@ -258,7 +258,7 @@ JS_EVENT_FUNCTION_IMPL(AddBody)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *body = js_safe_str(*str);
|
||||
switch_event_add_body(_event, "%s", body);
|
||||
info.GetReturnValue().Set(true);
|
||||
@@ -279,9 +279,9 @@ JS_EVENT_FUNCTION_IMPL(GetBody)
|
||||
}
|
||||
|
||||
if ((body = switch_event_get_body(_event))) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), body));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), body));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ JS_EVENT_FUNCTION_IMPL(GetType)
|
||||
}
|
||||
|
||||
event_name = switch_event_name(_event->event_id);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(event_name)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(event_name)));
|
||||
}
|
||||
|
||||
JS_EVENT_FUNCTION_IMPL(Serialize)
|
||||
@@ -311,7 +311,7 @@ JS_EVENT_FUNCTION_IMPL(Serialize)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *arg = js_safe_str(*str);
|
||||
if (!strcasecmp(arg, "xml")) {
|
||||
isxml++;
|
||||
@@ -325,7 +325,7 @@ JS_EVENT_FUNCTION_IMPL(Serialize)
|
||||
char *xmlstr;
|
||||
if ((xml = switch_event_xmlize(_event, SWITCH_VA_NONE))) {
|
||||
xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(xmlstr)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(xmlstr)));
|
||||
switch_xml_free(xml);
|
||||
switch_safe_free(xmlstr);
|
||||
} else {
|
||||
@@ -333,12 +333,12 @@ JS_EVENT_FUNCTION_IMPL(Serialize)
|
||||
}
|
||||
} else if (isjson) {
|
||||
if (switch_event_serialize_json(_event, &buf) == SWITCH_STATUS_SUCCESS) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(buf)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(buf)));
|
||||
switch_safe_free(buf);
|
||||
}
|
||||
} else {
|
||||
if (switch_event_serialize(_event, &buf, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(buf)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(buf)));
|
||||
switch_safe_free(buf);
|
||||
}
|
||||
}
|
||||
@@ -368,12 +368,12 @@ JS_EVENT_FUNCTION_IMPL(ChatExecute)
|
||||
|
||||
if (_event) {
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *app = js_safe_str(*str);
|
||||
string arg;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
if (*str2) {
|
||||
arg = js_safe_str(*str2);
|
||||
}
|
||||
@@ -408,12 +408,12 @@ JS_EVENT_FUNCTION_IMPL_STATIC(Destroy)
|
||||
JS_EVENT_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!strcmp(js_safe_str(*str), "ready")) {
|
||||
info.GetReturnValue().Set(_event ? true : false);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ void FSEventHandler::DoSubscribe(const v8::FunctionCallbackInfo<v8::Value>& info
|
||||
bool ret = false;
|
||||
|
||||
for (i = 0; i < info.Length(); i++) {
|
||||
String::Utf8Value str(info[i]);
|
||||
JsUtf8Value str(info[i]);
|
||||
switch_event_types_t etype;
|
||||
|
||||
if (custom) {
|
||||
@@ -226,7 +226,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(UnSubscribe)
|
||||
bool ret = false;
|
||||
|
||||
for (i = 0; i < info.Length(); i++) {
|
||||
String::Utf8Value str(info[i]);
|
||||
JsUtf8Value str(info[i]);
|
||||
switch_event_types_t etype;
|
||||
|
||||
if (custom) {
|
||||
@@ -263,7 +263,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(DeleteFilter)
|
||||
if (info.Length() < 1) {
|
||||
info.GetReturnValue().Set(false);
|
||||
} else {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *headerName = js_safe_str(*str);
|
||||
|
||||
if (zstr(headerName)) {
|
||||
@@ -295,8 +295,8 @@ JS_EVENTHANDLER_FUNCTION_IMPL(AddFilter)
|
||||
if (info.Length() < 2) {
|
||||
info.GetReturnValue().Set(false);
|
||||
} else {
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
const char *headerName = js_safe_str(*str1);
|
||||
const char *headerVal = js_safe_str(*str2);
|
||||
|
||||
@@ -326,7 +326,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(GetEvent)
|
||||
switch_event_t *pevent = NULL;
|
||||
|
||||
if (info.Length() > 0 && !info[0].IsEmpty()) {
|
||||
timeout = info[0]->Int32Value();
|
||||
timeout = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
@@ -359,7 +359,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(SendEvent)
|
||||
info.GetReturnValue().Set(false);
|
||||
} else {
|
||||
if (!info[0].IsEmpty() && info[0]->IsObject()) {
|
||||
FSEvent *evt = JSBase::GetInstance<FSEvent>(info[0]->ToObject());
|
||||
FSEvent *evt = JSBase::GetInstance<FSEvent>(info[0]->ToObject(js_current_context()).ToLocalChecked());
|
||||
switch_event_t **event;
|
||||
|
||||
if (!evt || !(event = evt->GetEvent())) {
|
||||
@@ -370,7 +370,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(SendEvent)
|
||||
if (info.Length() > 1) {
|
||||
if (!info[1].IsEmpty() && info[1]->IsObject()) {
|
||||
/* The second argument is a session object */
|
||||
FSSession *sess = JSBase::GetInstance<FSSession>(info[1]->ToObject());
|
||||
FSSession *sess = JSBase::GetInstance<FSSession>(info[1]->ToObject(js_current_context()).ToLocalChecked());
|
||||
switch_core_session_t *tmp;
|
||||
|
||||
if (sess && (tmp = sess->GetSession())) {
|
||||
@@ -378,7 +378,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(SendEvent)
|
||||
}
|
||||
} else {
|
||||
/* The second argument is a session uuid string */
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
session_uuid = js_safe_str(*str);
|
||||
}
|
||||
}
|
||||
@@ -410,7 +410,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(SendEvent)
|
||||
JS_EVENTHANDLER_FUNCTION_IMPL(ExecuteApi)
|
||||
{
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *cmd = js_safe_str(*str);
|
||||
string arg;
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
@@ -422,17 +422,17 @@ JS_EVENTHANDLER_FUNCTION_IMPL(ExecuteApi)
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
arg = js_safe_str(*str2);
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
switch_api_execute(cmd, arg.c_str(), NULL, &stream);
|
||||
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_str_nil((char *) stream.data)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_str_nil((char *) stream.data)));
|
||||
switch_safe_free(stream.data);
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), "-ERR"));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), "-ERR"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,16 +509,16 @@ JS_EVENTHANDLER_FUNCTION_IMPL(ExecuteBgApi)
|
||||
int sanity = 2000;
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
cmd = js_safe_str(*str);
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
arg = js_safe_str(*str2);
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
String::Utf8Value str2(info[2]);
|
||||
JsUtf8Value str2(info[2]);
|
||||
jobuuid = js_safe_str(*str2);
|
||||
}
|
||||
} else {
|
||||
@@ -553,7 +553,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL(ExecuteBgApi)
|
||||
switch_uuid_format(acs->uuid_str, &uuid);
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), acs->uuid_str));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), acs->uuid_str));
|
||||
|
||||
switch_thread_create(&thread, thd_attr, api_exec, acs, acs->pool);
|
||||
|
||||
|
||||
@@ -59,197 +59,197 @@ void *FSFile::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Close)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(CopyTo)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Flush)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(List)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(MkDir)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Open)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Read)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(ReadAll)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(ReadLn)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Remove)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(RenameTo)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Seek)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(ToString)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(ToURL)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(Write)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(WriteAll)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_FUNCTION_IMPL(WriteLn)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropCanAppend)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropCanRead)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropCanReplace)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropCanWrite)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropCreationTime)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropExists)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropHasAutoFlush)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropHasRandomAccess)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropIsDirectory)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropIsFile)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropIsNative)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropIsOpen)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropLastModified)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropLength)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropMode)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropName)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropParent)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropPath)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropPosition)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_SET_PROPERTY_IMPL(SetPropPosition)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropSize)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
JS_FILE_GET_PROPERTY_IMPL(GetPropType)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Not yet implemented"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Not yet implemented"));
|
||||
}
|
||||
|
||||
static const js_function_t file_proc[] = {
|
||||
|
||||
@@ -79,8 +79,8 @@ void *FSFileIO::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
|
||||
if (info.Length() > 1) {
|
||||
const char *path, *flags_str;
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
path = js_safe_str(*str1);
|
||||
flags_str = js_safe_str(*str2);
|
||||
|
||||
@@ -113,7 +113,7 @@ void *FSFileIO::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
if (switch_file_open(&fd, path, flags, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
char *err = switch_mprintf("Cannot Open File: %s", path);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return NULL;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ void *FSFileIO::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
return fio;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid Args"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid Args"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ JS_FILEIO_FUNCTION_IMPL(Read)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
bytes = info[0]->Int32Value();
|
||||
bytes = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (bytes) {
|
||||
@@ -169,7 +169,7 @@ JS_FILEIO_FUNCTION_IMPL(GetData)
|
||||
if (!_buflen || !_buf) {
|
||||
info.GetReturnValue().Set(false);
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), _buf));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), _buf));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ JS_FILEIO_FUNCTION_IMPL(Write)
|
||||
|
||||
if (info.Length() > 0) {
|
||||
char *data = NULL;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
data = *str;
|
||||
|
||||
if (data) {
|
||||
@@ -201,19 +201,19 @@ JS_FILEIO_FUNCTION_IMPL(Write)
|
||||
JS_FILEIO_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
const char *prop = js_safe_str(*str);
|
||||
|
||||
if (!strcmp(prop, "path")) {
|
||||
if (_path) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), _path));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), _path));
|
||||
} else {
|
||||
info.GetReturnValue().Set(false);
|
||||
}
|
||||
} else if (!strcmp(prop, "open")) {
|
||||
info.GetReturnValue().Set(_fd ? true : false);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ size_t FSGlobal::HashCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
*p = '\0';
|
||||
|
||||
// Add data to hash
|
||||
args->Set(String::NewFromUtf8(config_data->isolate, line), String::NewFromUtf8(config_data->isolate, js_safe_str(val)));
|
||||
js_obj_set(args, js_new_string(config_data->isolate, line), js_new_string(config_data->isolate, js_safe_str(val)));
|
||||
}
|
||||
|
||||
line = nextline;
|
||||
@@ -149,14 +149,14 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash)
|
||||
int saveDepth = 0;
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value url(info[0]);
|
||||
JsUtf8Value url(info[0]);
|
||||
|
||||
if (info.Length() > 1 && info[1]->IsString()) {
|
||||
/* Cast to string */
|
||||
Local<String> str = Local<String>::Cast(info[1]);
|
||||
|
||||
/* Try to get existing variable */
|
||||
Local<Value> obj = info.GetIsolate()->GetCurrentContext()->Global()->Get(str);
|
||||
Local<Value> obj = js_obj_get(info.GetIsolate()->GetCurrentContext()->Global(), str);
|
||||
|
||||
if (!obj.IsEmpty() && obj->IsArray()) {
|
||||
/* The existing var is an array, use it */
|
||||
@@ -164,11 +164,11 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash)
|
||||
} else if (obj.IsEmpty() || obj->IsUndefined()) {
|
||||
/* No existing var (or an existing that is undefined), create a new one */
|
||||
Local<Array> arguments = Array::New(info.GetIsolate());
|
||||
info.GetIsolate()->GetCurrentContext()->Global()->Set(str, arguments);
|
||||
js_obj_set(info.GetIsolate()->GetCurrentContext()->Global(), str, arguments);
|
||||
config_data.hashObject.Reset(info.GetIsolate(), arguments);
|
||||
} else {
|
||||
/* The var exists, but is wrong type - exit with error */
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Second argument is the name of an existing var of the wrong type"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Second argument is the name of an existing var of the wrong type"));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash)
|
||||
config_data.hashObject.Reset(info.GetIsolate(), Local<Array>::Cast(info[1]));
|
||||
} else if (info.Length() > 1) {
|
||||
/* The var exists, but is wrong type - exit with error */
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Second argument is of the wrong type"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Second argument is of the wrong type"));
|
||||
|
||||
return;
|
||||
} else {
|
||||
@@ -188,7 +188,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash)
|
||||
|
||||
curl_handle = switch_curl_easy_init();
|
||||
if (!curl_handle) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session."));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to initiate curl easy session."));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -213,9 +213,9 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash)
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
|
||||
/* Return the hash */
|
||||
info.GetReturnValue().Set(config_data.hashObject);
|
||||
info.GetReturnValue().Set(js_local(config_data.hashObject));
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,15 +229,15 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLFile)
|
||||
|
||||
if (info.Length() > 1) {
|
||||
const char *url = NULL, *filename = NULL;
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
|
||||
url = js_safe_str(*str1);
|
||||
filename = js_safe_str(*str2);
|
||||
|
||||
curl_handle = switch_curl_easy_init();
|
||||
if (!curl_handle) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session."));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to initiate curl easy session."));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLFile)
|
||||
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,16 +285,16 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL)
|
||||
|
||||
if (info.Length() >= 1) {
|
||||
const char *url;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
|
||||
url = js_safe_str(*str);
|
||||
if (info.Length() > 1) {
|
||||
buffer_size = info[1]->Int32Value();
|
||||
buffer_size = info[1]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
curl_handle = switch_curl_easy_init();
|
||||
if (!curl_handle) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session."));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to initiate curl easy session."));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -310,7 +310,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL)
|
||||
config_data.bufferDataLength = 0;
|
||||
|
||||
if (config_data.buffer == NULL) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to allocate data buffer."));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to allocate data buffer."));
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
|
||||
return;
|
||||
@@ -330,7 +330,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL)
|
||||
|
||||
if (code == CURLE_OK) {
|
||||
config_data.buffer[config_data.bufferDataLength] = 0;
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(config_data.buffer)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(config_data.buffer)));
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Curl returned error %u\n", (unsigned) code);
|
||||
info.GetReturnValue().Set(false);
|
||||
@@ -338,7 +338,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL)
|
||||
|
||||
free(config_data.buffer);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Exit)
|
||||
|
||||
if (info.Length() > 0) {
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
|
||||
if (*str) {
|
||||
JSMain::ExitScript(info.GetIsolate(), *str);
|
||||
@@ -374,7 +374,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Log)
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
|
||||
if ((level_str = *str)) {
|
||||
level = switch_log_str2level(level_str);
|
||||
@@ -383,7 +383,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Log)
|
||||
}
|
||||
}
|
||||
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
if ((msg = *str2) && *msg != '\0') {
|
||||
const char lastchar = msg[strlen(msg)-1];
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "console_log", line, NULL, level, "%s%s", msg, lastchar != '\n' ? "\n" : "");
|
||||
@@ -391,7 +391,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Log)
|
||||
return;
|
||||
}
|
||||
} else if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
if ((msg = *str) && *msg != '\0') {
|
||||
const char lastchar = msg[strlen(msg)-1];
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "console_log", line, NULL, level, "%s%s", msg, lastchar != '\n' ? "\n" : "");
|
||||
@@ -411,8 +411,8 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(GlobalSet)
|
||||
bool tf = true;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
var_name = js_safe_str(*str1);
|
||||
val = js_safe_str(*str2);
|
||||
if (info.Length() == 2) {
|
||||
@@ -420,7 +420,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(GlobalSet)
|
||||
info.GetReturnValue().Set(true);
|
||||
return;
|
||||
} else {
|
||||
String::Utf8Value str3(info[2]);
|
||||
JsUtf8Value str3(info[2]);
|
||||
val2 = js_safe_str(*str3);
|
||||
if (switch_core_set_var_conditional(var_name, val, val2) != SWITCH_TRUE) {
|
||||
tf = false;
|
||||
@@ -430,7 +430,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(GlobalSet)
|
||||
}
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "var name not supplied!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "var name not supplied!"));
|
||||
}
|
||||
|
||||
JS_GLOBAL_FUNCTION_IMPL_STATIC(GlobalGet)
|
||||
@@ -441,15 +441,15 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(GlobalGet)
|
||||
char *val = NULL;
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
var_name = js_safe_str(*str);
|
||||
val = switch_core_get_variable_dup(var_name);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(val)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(val)));
|
||||
switch_safe_free(val);
|
||||
return;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "var name not supplied!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "var name not supplied!"));
|
||||
}
|
||||
|
||||
JS_GLOBAL_FUNCTION_IMPL_STATIC(Include)
|
||||
@@ -457,13 +457,13 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Include)
|
||||
JS_CHECK_SCRIPT_STATE();
|
||||
if (info.Length() < 1) {
|
||||
/* Bad arguments, return exception */
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
} else {
|
||||
/* Try to get the current script path */
|
||||
string scriptPath = "";
|
||||
Handle<Value> val = info.GetIsolate()->GetCurrentContext()->Global()->Get(String::NewFromUtf8(info.GetIsolate(), "scriptPath"));
|
||||
Local<Value> val = js_obj_get(info.GetIsolate()->GetCurrentContext()->Global(), js_new_string(info.GetIsolate(), "scriptPath"));
|
||||
if (!val.IsEmpty() && val->IsString()) {
|
||||
String::Utf8Value tmp(val);
|
||||
JsUtf8Value tmp(val);
|
||||
if (*tmp) {
|
||||
scriptPath = *tmp;
|
||||
}
|
||||
@@ -472,7 +472,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Include)
|
||||
/* Loop all arguments until we find a valid file */
|
||||
for (int i = 0; i < info.Length(); i++) {
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(info[i]);
|
||||
JsUtf8Value str(info[i]);
|
||||
char *path = NULL;
|
||||
const char *script_name = NULL;
|
||||
|
||||
@@ -508,12 +508,12 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Include)
|
||||
if (script.IsEmpty()) {
|
||||
info.GetReturnValue().Set(false);
|
||||
} else {
|
||||
info.GetReturnValue().Set(script.ToLocalChecked()->Run());
|
||||
info.GetReturnValue().Set(js_run_script(script.ToLocalChecked()));
|
||||
}
|
||||
#else
|
||||
Handle<String> source = String::NewFromUtf8(info.GetIsolate(), js_file.c_str());
|
||||
Handle<Script> script = Script::Compile(source, info[i]);
|
||||
info.GetReturnValue().Set(script->Run());
|
||||
Local<String> source = js_new_string(info.GetIsolate(), js_file.c_str());
|
||||
Local<Script> script = Script::Compile(source, info[i]);
|
||||
info.GetReturnValue().Set(js_run_script(script));
|
||||
#endif
|
||||
switch_safe_free(path);
|
||||
return;
|
||||
@@ -522,7 +522,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Include)
|
||||
switch_safe_free(path);
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to include javascript file"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to include javascript file"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,13 +533,13 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Sleep)
|
||||
int32_t msec = 0;
|
||||
|
||||
if (info.Length() > 0) {
|
||||
msec = info[0]->Int32Value();
|
||||
msec = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (msec) {
|
||||
switch_yield(msec * 1000);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "No time specified"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "No time specified"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Use)
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
char *mod_name = *str;
|
||||
|
||||
if (mod_name) {
|
||||
@@ -560,12 +560,12 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Use)
|
||||
mp->v8_mod_load(info);
|
||||
} else {
|
||||
char *err = switch_mprintf("Error loading %s", mod_name);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,7 +575,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(ApiExecute)
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *cmd = js_safe_str(*str);
|
||||
string arg;
|
||||
switch_core_session_t *session = NULL;
|
||||
@@ -588,13 +588,13 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(ApiExecute)
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
arg = js_safe_str(*str2);
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
if (!info[2].IsEmpty() && info[2]->IsObject()) {
|
||||
Handle<Object> session_obj = Handle<Object>::Cast(info[2]);
|
||||
Local<Object> session_obj = Local<Object>::Cast(info[2]);
|
||||
FSSession *obj = JSBase::GetInstance<FSSession>(session_obj);
|
||||
if (obj) {
|
||||
session = obj->GetSession();
|
||||
@@ -605,10 +605,10 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(ApiExecute)
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
switch_api_execute(cmd, arg.c_str(), session, &stream);
|
||||
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_str_nil((char *) stream.data)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_str_nil((char *) stream.data)));
|
||||
switch_safe_free(stream.data);
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,37 +619,37 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Email)
|
||||
string to, from, headers, body, file, convert_cmd, convert_ext;
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
to = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
from = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
String::Utf8Value str(info[2]);
|
||||
JsUtf8Value str(info[2]);
|
||||
headers = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
String::Utf8Value str(info[3]);
|
||||
JsUtf8Value str(info[3]);
|
||||
body = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 4) {
|
||||
String::Utf8Value str(info[4]);
|
||||
JsUtf8Value str(info[4]);
|
||||
file = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 5) {
|
||||
String::Utf8Value str(info[5]);
|
||||
JsUtf8Value str(info[5]);
|
||||
convert_cmd = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 6) {
|
||||
String::Utf8Value str(info[6]);
|
||||
JsUtf8Value str(info[6]);
|
||||
convert_ext = js_safe_str(*str);
|
||||
}
|
||||
|
||||
@@ -666,8 +666,8 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Bridge)
|
||||
JS_CHECK_SCRIPT_STATE();
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
FSSession *jss_a = NULL, *jss_b = NULL;
|
||||
Handle<Object> obj_a;
|
||||
Handle<Object> obj_b;
|
||||
Local<Object> obj_a;
|
||||
Local<Object> obj_b;
|
||||
void *bp = NULL;
|
||||
switch_input_callback_function_t dtmf_func = NULL;
|
||||
FSInputCallbackState cb_state;
|
||||
@@ -676,34 +676,34 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(Bridge)
|
||||
|
||||
if (info.Length() > 1) {
|
||||
if (info[0]->IsObject()) {
|
||||
obj_a = Handle<Object>::Cast(info[0]);
|
||||
obj_a = Local<Object>::Cast(info[0]);
|
||||
|
||||
if (!(jss_a = JSBase::GetInstance<FSSession>(obj_a))) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot find session A"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot find session A"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (info[1]->IsObject()) {
|
||||
obj_b = Handle<Object>::Cast(info[1]);
|
||||
obj_b = Local<Object>::Cast(info[1]);
|
||||
if (!(jss_b = JSBase::GetInstance<FSSession>(obj_b))) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot find session B"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot find session B"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(jss_a && jss_a->GetSession())) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "session A is not ready!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "session A is not ready!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(jss_b && jss_b->GetSession())) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "session B is not ready!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "session B is not ready!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[2]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[2]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
@@ -738,7 +738,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(System)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
cmd = *str;
|
||||
if (cmd) {
|
||||
result = switch_system(cmd, SWITCH_TRUE);
|
||||
@@ -747,7 +747,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(System)
|
||||
}
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
|
||||
JS_GLOBAL_FUNCTION_IMPL_STATIC(FileDelete)
|
||||
@@ -759,7 +759,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FileDelete)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
path = *str;
|
||||
if (path) {
|
||||
if ((switch_file_remove(path, NULL)) == SWITCH_STATUS_SUCCESS) {
|
||||
@@ -769,20 +769,20 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FileDelete)
|
||||
}
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
|
||||
/* Internal Version function accessable from JS - used to get the current V8 version */
|
||||
JS_GLOBAL_FUNCTION_IMPL_STATIC(Version)
|
||||
{
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), V8::GetVersion()));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), V8::GetVersion()));
|
||||
}
|
||||
|
||||
/* TaskId assigned to the script - used to manage the task */
|
||||
JS_GLOBAL_FUNCTION_IMPL_STATIC(Id)
|
||||
{
|
||||
js_isolate_private_data_t *private_data = (js_isolate_private_data_t*)info.GetIsolate()->GetData(ISOLATE_DATA_PRIVATE);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), private_data->str_task_id.c_str()));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), private_data->str_task_id.c_str()));
|
||||
}
|
||||
|
||||
static const js_function_t fs_proc[] = {
|
||||
|
||||
@@ -102,19 +102,19 @@ void *FSODBC::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
int32_t blen = 1024;
|
||||
|
||||
if (info.Length() < 3) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid parameters"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid parameters"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
String::Utf8Value str3(info[2]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
JsUtf8Value str3(info[2]);
|
||||
dsn = *str1;
|
||||
username = *str2;
|
||||
password = *str3;
|
||||
|
||||
if (info.Length() > 3) {
|
||||
int32_t len = info[3]->Int32Value();
|
||||
int32_t len = info[3]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
|
||||
if (len > 0) {
|
||||
blen = len;
|
||||
@@ -134,13 +134,13 @@ void *FSODBC::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
}
|
||||
|
||||
if (!odbc_obj) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to create new ODBC instance"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed to create new ODBC instance"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(odbc_obj->_colbuf = (SQLCHAR *) malloc(blen))) {
|
||||
delete odbc_obj;
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Memory error"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Memory error"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ JS_ODBC_FUNCTION_IMPL(Execute)
|
||||
const char *sql;
|
||||
bool tf = false;
|
||||
SQLHSTMT local_stmt;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
|
||||
if (info.Length() < 1) {
|
||||
goto done;
|
||||
@@ -201,7 +201,7 @@ JS_ODBC_FUNCTION_IMPL(Exec)
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
const char *sql;
|
||||
bool tf = false;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
|
||||
if (info.Length() < 1) {
|
||||
goto done;
|
||||
@@ -307,7 +307,7 @@ JS_ODBC_FUNCTION_IMPL(GetData)
|
||||
goto done;
|
||||
}
|
||||
|
||||
Handle<Array> arg = Array::New(GetIsolate(), nColumns);
|
||||
Local<Array> arg = Array::New(GetIsolate(), nColumns);
|
||||
|
||||
for (x = 1; x <= nColumns; x++) {
|
||||
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
|
||||
@@ -321,9 +321,9 @@ JS_ODBC_FUNCTION_IMPL(GetData)
|
||||
|
||||
if (name) {
|
||||
if (SQL_NULL_DATA == pcbValue) {
|
||||
arg->Set(String::NewFromUtf8(GetIsolate(), (const char *)name), Null(info.GetIsolate()));
|
||||
js_obj_set(arg, js_new_string(GetIsolate(), (const char *)name), Null(info.GetIsolate()));
|
||||
} else {
|
||||
arg->Set(String::NewFromUtf8(GetIsolate(), (const char *)name), String::NewFromUtf8(GetIsolate(), data ? (const char *)data : ""));
|
||||
js_obj_set(arg, js_new_string(GetIsolate(), (const char *)name), js_new_string(GetIsolate(), data ? (const char *)data : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,12 +369,12 @@ JS_ODBC_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!strcmp(js_safe_str(*str), "name")) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), _dsn.length() > 0 ? _dsn.c_str() : ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), _dsn.length() > 0 ? _dsn.c_str() : ""));
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,8 @@ JS_PCRE_FUNCTION_IMPL(Compile)
|
||||
const char *string, *regex_string;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
string = js_safe_str(*str1);
|
||||
regex_string = js_safe_str(*str2);
|
||||
switch_regex_match_safe_free(this->_match_data);
|
||||
@@ -82,7 +82,7 @@ JS_PCRE_FUNCTION_IMPL(Compile)
|
||||
this->_proceed = switch_regex_perform(this->_str, regex_string, &this->_re, &this->_match_data);
|
||||
info.GetReturnValue().Set(this->_proceed ? true : false);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid args"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid args"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,34 +93,34 @@ JS_PCRE_FUNCTION_IMPL(Substitute)
|
||||
char *substituted;
|
||||
|
||||
if (!this->_proceed) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "REGEX is not compiled or has no matches"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "REGEX is not compiled or has no matches"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
uint32_t len;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
subst_string = js_safe_str(*str);
|
||||
len = (uint32_t) (strlen(this->_str) + strlen(subst_string) + 10) * this->_proceed;
|
||||
substituted = (char *)malloc(len);
|
||||
switch_assert(substituted != NULL);
|
||||
switch_perform_substitution(this->_match_data, subst_string, substituted, len);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), substituted));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), substituted));
|
||||
free(substituted);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid Args"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid Args"));
|
||||
}
|
||||
}
|
||||
|
||||
JS_PCRE_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!strcmp(js_safe_str(*str), "ready")) {
|
||||
info.GetReturnValue().Set(true);
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ JS_REQUEST_FUNCTION_IMPL(Write)
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
if (*str) this->_stream->write_function(this->_stream, "%s", *str);
|
||||
info.GetReturnValue().Set(true);
|
||||
return;
|
||||
@@ -77,8 +77,8 @@ JS_REQUEST_FUNCTION_IMPL(AddHeader)
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
const char *hname = js_safe_str(*str1);
|
||||
const char *hval = js_safe_str(*str2);
|
||||
switch_event_add_header_string(this->_stream->param_event, SWITCH_STACK_BOTTOM, hname, hval);
|
||||
@@ -94,10 +94,10 @@ JS_REQUEST_FUNCTION_IMPL(GetHeader)
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *hname = js_safe_str(*str);
|
||||
char *val = switch_event_get_header(this->_stream->param_event, hname);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(val)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(val)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ JS_REQUEST_FUNCTION_IMPL(DumpEnv)
|
||||
string how = "text";
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
how = js_safe_str(*str);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ JS_REQUEST_FUNCTION_IMPL(DumpEnv)
|
||||
if ((xml = switch_event_xmlize(this->_stream->param_event, SWITCH_VA_NONE))) {
|
||||
char *xmlstr;
|
||||
if ((xmlstr = switch_xml_toxml(xml, SWITCH_FALSE))) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), xmlstr));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), xmlstr));
|
||||
switch_safe_free(xmlstr);
|
||||
switch_xml_free(xml);
|
||||
return;
|
||||
@@ -130,7 +130,7 @@ JS_REQUEST_FUNCTION_IMPL(DumpEnv)
|
||||
} else if (!strcasecmp(how.c_str(), "json")) {
|
||||
char *buf = NULL;
|
||||
if (switch_event_serialize_json(this->_stream->param_event, &buf) == SWITCH_STATUS_SUCCESS) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(buf)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(buf)));
|
||||
switch_safe_free(buf);
|
||||
return;
|
||||
} else {
|
||||
@@ -139,7 +139,7 @@ JS_REQUEST_FUNCTION_IMPL(DumpEnv)
|
||||
} else {
|
||||
char *buf = NULL;
|
||||
if (switch_event_serialize(this->_stream->param_event, &buf, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(buf)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(buf)));
|
||||
switch_safe_free(buf);
|
||||
return;
|
||||
} else {
|
||||
@@ -153,16 +153,16 @@ JS_REQUEST_FUNCTION_IMPL(DumpEnv)
|
||||
JS_REQUEST_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!strcmp(js_safe_str(*str), "command")) {
|
||||
if (this->_cmd) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), this->_cmd));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), this->_cmd));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,19 +40,19 @@ using namespace v8;
|
||||
static const char js_class_name[] = "Session";
|
||||
|
||||
#define METHOD_SANITY_CHECK() if (!this->_session) {\
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "No session is active, you must have an active session before calling this method"));\
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "No session is active, you must have an active session before calling this method"));\
|
||||
return;\
|
||||
} else CheckHangupHook(this, NULL)
|
||||
|
||||
#define CHANNEL_SANITY_CHECK() do {\
|
||||
if (!switch_channel_ready(channel)) {\
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Session is not active!"));\
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Session is not active!"));\
|
||||
return;\
|
||||
}\
|
||||
if (!((switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA)))) {\
|
||||
switch_channel_pre_answer(channel);\
|
||||
if (!((switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA)))) {\
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Session is not answered!"));\
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Session is not answered!"));\
|
||||
return;\
|
||||
}\
|
||||
}\
|
||||
@@ -60,14 +60,14 @@ static const char js_class_name[] = "Session";
|
||||
|
||||
#define CHANNEL_SANITY_CHECK_ANSWER() do {\
|
||||
if (!switch_channel_ready(channel)) {\
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Session is not active!"));\
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Session is not active!"));\
|
||||
return;\
|
||||
}\
|
||||
} while (foo == 1)
|
||||
|
||||
#define CHANNEL_MEDIA_SANITY_CHECK() do {\
|
||||
if (!switch_channel_media_ready(channel)) {\
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Session is not in media mode!"));\
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Session is not in media mode!"));\
|
||||
return;\
|
||||
}\
|
||||
} while (foo == 1)
|
||||
@@ -192,15 +192,15 @@ switch_status_t FSSession::CommonCallback(switch_core_session_t *session, void *
|
||||
FSInputCallbackState *cb_state = (FSInputCallbackState *)buf;
|
||||
switch_event_t *event = NULL;
|
||||
int argc = 0;
|
||||
Handle<Value> argv[4];
|
||||
Handle<Object> Event;
|
||||
Local<Value> argv[4];
|
||||
Local<Object> Event;
|
||||
bool ret = true;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
/* Session sanity check first */
|
||||
if (!cb_state->session_state || !cb_state->session_state->_session) {
|
||||
if (cb_state->session_state && cb_state->session_state->GetIsolate()) {
|
||||
cb_state->session_state->GetIsolate()->ThrowException(String::NewFromUtf8(cb_state->session_state->GetIsolate(), "No session is active, you must have an active session before calling this method"));
|
||||
cb_state->session_state->GetIsolate()->ThrowException(js_new_string(cb_state->session_state->GetIsolate(), "No session is active, you must have an active session before calling this method"));
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No session is active, you must have an active session before calling this method\n");
|
||||
}
|
||||
@@ -235,7 +235,7 @@ switch_status_t FSSession::CommonCallback(switch_core_session_t *session, void *
|
||||
if ((event = (switch_event_t *) input)) {
|
||||
Event = FSEvent::New(event, "", cb_state->session_state->GetOwner());
|
||||
if (!Event.IsEmpty()) {
|
||||
argv[argc++] = String::NewFromUtf8(isolate, "event");
|
||||
argv[argc++] = js_new_string(isolate, "event");
|
||||
argv[argc++] = Local<Object>::New(isolate, Event);
|
||||
}
|
||||
}
|
||||
@@ -250,7 +250,7 @@ switch_status_t FSSession::CommonCallback(switch_core_session_t *session, void *
|
||||
if (dtmf) {
|
||||
Event = FSDTMF::New(dtmf, "", cb_state->session_state->GetOwner());
|
||||
if (!Event.IsEmpty()) {
|
||||
argv[argc++] = String::NewFromUtf8(isolate, "dtmf");
|
||||
argv[argc++] = js_new_string(isolate, "dtmf");
|
||||
argv[argc++] = Local<Object>::New(isolate, Event);
|
||||
} else {
|
||||
goto done;
|
||||
@@ -268,10 +268,10 @@ switch_status_t FSSession::CommonCallback(switch_core_session_t *session, void *
|
||||
|
||||
if (ret) {
|
||||
if (!cb_state->function.IsEmpty()) {
|
||||
Handle<Function> func = Local<Function>::New(isolate, cb_state->function);
|
||||
Local<Function> func = Local<Function>::New(isolate, cb_state->function);
|
||||
|
||||
if (func->IsFunction()) {
|
||||
Handle<Value> res = func->Call(isolate->GetCurrentContext()->Global(), argc, argv);
|
||||
Local<Value> res = js_call(func, isolate->GetCurrentContext()->Global(), argc, argv);
|
||||
|
||||
if (!res.IsEmpty()) {
|
||||
cb_state->ret.Reset(isolate, res);
|
||||
@@ -309,8 +309,8 @@ switch_status_t FSSession::StreamInputCallback(switch_core_session_t *session, v
|
||||
}
|
||||
|
||||
if (!cb_state->ret.IsEmpty()) {
|
||||
Handle<Value> tmp = Local<Value>::New(obj->GetOwner()->GetIsolate(), cb_state->ret);
|
||||
String::Utf8Value str(tmp);
|
||||
Local<Value> tmp = Local<Value>::New(obj->GetOwner()->GetIsolate(), cb_state->ret);
|
||||
JsUtf8Value str(tmp);
|
||||
const char *ret = js_safe_str(*str);
|
||||
|
||||
if (!strncasecmp(ret, "speed", 5)) {
|
||||
@@ -420,8 +420,8 @@ switch_status_t FSSession::RecordInputCallback(switch_core_session_t *session, v
|
||||
}
|
||||
|
||||
if (!cb_state->ret.IsEmpty()) {
|
||||
Handle<Value> tmp = Local<Value>::New(obj->GetOwner()->GetIsolate(), cb_state->ret);
|
||||
String::Utf8Value str(tmp);
|
||||
Local<Value> tmp = Local<Value>::New(obj->GetOwner()->GetIsolate(), cb_state->ret);
|
||||
JsUtf8Value str(tmp);
|
||||
const char *ret = js_safe_str(*str);
|
||||
|
||||
if (!strcasecmp(ret, "pause")) {
|
||||
@@ -461,8 +461,8 @@ switch_status_t FSSession::CollectInputCallback(switch_core_session_t *session,
|
||||
}
|
||||
|
||||
if (!cb_state->ret.IsEmpty()) {
|
||||
Handle<Value> tmp = Local<Value>::New(obj->GetOwner()->GetIsolate(), cb_state->ret);
|
||||
String::Utf8Value str(tmp);
|
||||
Local<Value> tmp = Local<Value>::New(obj->GetOwner()->GetIsolate(), cb_state->ret);
|
||||
JsUtf8Value str(tmp);
|
||||
ret = js_safe_str(*str);
|
||||
|
||||
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
|
||||
@@ -525,7 +525,7 @@ JS_SESSION_FUNCTION_IMPL(RecordFile)
|
||||
CHANNEL_MEDIA_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
file_name = js_safe_str(*str);
|
||||
if (zstr(file_name.c_str())) {
|
||||
info.GetReturnValue().Set(false);
|
||||
@@ -534,7 +534,7 @@ JS_SESSION_FUNCTION_IMPL(RecordFile)
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.session_state = this;
|
||||
@@ -550,15 +550,15 @@ JS_SESSION_FUNCTION_IMPL(RecordFile)
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
limit = info[3]->Int32Value();
|
||||
limit = info[3]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (info.Length() > 4) {
|
||||
fh.thresh = info[4]->Int32Value();
|
||||
fh.thresh = info[4]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (info.Length() > 5) {
|
||||
fh.silence_hits = info[5]->Int32Value();
|
||||
fh.silence_hits = info[5]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,7 +569,7 @@ JS_SESSION_FUNCTION_IMPL(RecordFile)
|
||||
args.buflen = len;
|
||||
|
||||
JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_record_file(this->_session, &fh, file_name.c_str(), &args, limit));
|
||||
info.GetReturnValue().Set(cb_state.ret);
|
||||
info.GetReturnValue().Set(js_local(cb_state.ret));
|
||||
|
||||
CheckHangupHook(this, &ret);
|
||||
if (!ret) JSMain::ExitScript(info.GetIsolate(), NULL);
|
||||
@@ -594,7 +594,7 @@ JS_SESSION_FUNCTION_IMPL(CollectInput)
|
||||
CHANNEL_MEDIA_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[0]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[0]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
@@ -612,10 +612,10 @@ JS_SESSION_FUNCTION_IMPL(CollectInput)
|
||||
}
|
||||
|
||||
if (info.Length() == 3) {
|
||||
abs_timeout = info[2]->Int32Value();
|
||||
abs_timeout = info[2]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
} else if (info.Length() > 3) {
|
||||
digit_timeout = info[2]->Int32Value();
|
||||
abs_timeout = info[3]->Int32Value();
|
||||
digit_timeout = info[2]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
abs_timeout = info[3]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
cb_state.ret.Reset(info.GetIsolate(), Boolean::New(info.GetIsolate(), false));
|
||||
@@ -624,7 +624,7 @@ JS_SESSION_FUNCTION_IMPL(CollectInput)
|
||||
args.buflen = len;
|
||||
|
||||
JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_collect_digits_callback(this->_session, &args, digit_timeout, abs_timeout));
|
||||
info.GetReturnValue().Set(cb_state.ret);
|
||||
info.GetReturnValue().Set(js_local(cb_state.ret));
|
||||
|
||||
CheckHangupHook(this, &ret);
|
||||
if (!ret) JSMain::ExitScript(info.GetIsolate(), NULL);
|
||||
@@ -651,24 +651,24 @@ JS_SESSION_FUNCTION_IMPL(SayPhrase)
|
||||
CHANNEL_MEDIA_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
phrase_name = js_safe_str(*str);
|
||||
if (zstr(phrase_name.c_str())) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid phrase name"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid phrase name"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
phrase_data = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
String::Utf8Value str(info[2]);
|
||||
JsUtf8Value str(info[2]);
|
||||
tmp = js_safe_str(*str);
|
||||
if (!zstr(tmp.c_str())) {
|
||||
phrase_lang = std::move(tmp);
|
||||
@@ -676,7 +676,7 @@ JS_SESSION_FUNCTION_IMPL(SayPhrase)
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[3]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[3]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
@@ -699,7 +699,7 @@ JS_SESSION_FUNCTION_IMPL(SayPhrase)
|
||||
args.buflen = len;
|
||||
|
||||
JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_phrase_macro(this->_session, phrase_name.c_str(), phrase_data.c_str(), phrase_lang.c_str(), &args));
|
||||
info.GetReturnValue().Set(cb_state.ret);
|
||||
info.GetReturnValue().Set(js_local(cb_state.ret));
|
||||
|
||||
CheckHangupHook(this, &ret);
|
||||
if (!ret) JSMain::ExitScript(info.GetIsolate(), NULL);
|
||||
@@ -713,7 +713,7 @@ bool FSSession::CheckHangupHook(FSSession *obj, bool *ret)
|
||||
|
||||
Isolate *isolate = obj->GetIsolate();
|
||||
HandleScope handle_scope(isolate);
|
||||
Handle<Value> argv[2];
|
||||
Local<Value> argv[2];
|
||||
int argc = 0;
|
||||
bool res = true;
|
||||
string resp;
|
||||
@@ -723,19 +723,19 @@ bool FSSession::CheckHangupHook(FSSession *obj, bool *ret)
|
||||
argv[argc++] = Local<Object>::New(obj->GetOwner()->GetIsolate(), obj->GetJavaScriptObject());
|
||||
|
||||
if (obj->_hook_state == CS_HANGUP) {
|
||||
argv[argc++] = String::NewFromUtf8(isolate, "hangup");
|
||||
argv[argc++] = js_new_string(isolate, "hangup");
|
||||
} else {
|
||||
argv[argc++] = String::NewFromUtf8(isolate, "transfer");
|
||||
argv[argc++] = js_new_string(isolate, "transfer");
|
||||
}
|
||||
|
||||
// Run the hangup hook
|
||||
Handle<Function> func = Local<Function>::New(isolate, obj->_on_hangup);
|
||||
Local<Function> func = Local<Function>::New(isolate, obj->_on_hangup);
|
||||
|
||||
if (!func.IsEmpty() && func->IsFunction()) {
|
||||
Handle<Value> res = func->Call(isolate->GetCurrentContext()->Global(), argc, argv);
|
||||
Local<Value> res = js_call(func, isolate->GetCurrentContext()->Global(), argc, argv);
|
||||
|
||||
if (!res.IsEmpty()) {
|
||||
String::Utf8Value str(res);
|
||||
JsUtf8Value str(res);
|
||||
resp = js_safe_str(*str);
|
||||
}
|
||||
}
|
||||
@@ -785,7 +785,7 @@ JS_SESSION_FUNCTION_IMPL(SetHangupHook)
|
||||
}
|
||||
|
||||
if (info.Length() > 0) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[0]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[0]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
this->_on_hangup.Reset(info.GetIsolate(), func);
|
||||
@@ -819,16 +819,16 @@ JS_SESSION_FUNCTION_IMPL(StreamFile)
|
||||
CHANNEL_MEDIA_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
file_name = js_safe_str(*str);
|
||||
if (zstr(file_name.c_str())) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid filename"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid filename"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
@@ -846,7 +846,7 @@ JS_SESSION_FUNCTION_IMPL(StreamFile)
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
fh.samples = info[3]->Int32Value();
|
||||
fh.samples = info[3]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if ((prebuf = switch_channel_get_variable(channel, "stream_prebuffer"))) {
|
||||
@@ -862,7 +862,7 @@ JS_SESSION_FUNCTION_IMPL(StreamFile)
|
||||
args.buf = bp;
|
||||
args.buflen = len;
|
||||
JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_play_file(this->_session, &fh, file_name.c_str(), &args));
|
||||
info.GetReturnValue().Set(cb_state.ret);
|
||||
info.GetReturnValue().Set(js_local(cb_state.ret));
|
||||
|
||||
switch_snprintf(posbuf, sizeof(posbuf), "%u", fh.offset_pos);
|
||||
switch_channel_set_variable(channel, "last_file_position", posbuf);
|
||||
@@ -890,7 +890,7 @@ JS_SESSION_FUNCTION_IMPL(Sleep)
|
||||
CHANNEL_MEDIA_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
ms = info[0]->Int32Value();
|
||||
ms = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (ms <= 0) {
|
||||
@@ -898,7 +898,7 @@ JS_SESSION_FUNCTION_IMPL(Sleep)
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
@@ -916,7 +916,7 @@ JS_SESSION_FUNCTION_IMPL(Sleep)
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
sync = info[2]->Int32Value();
|
||||
sync = info[2]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
cb_state.ret.Reset(info.GetIsolate(), Boolean::New(info.GetIsolate(), false));
|
||||
@@ -924,7 +924,7 @@ JS_SESSION_FUNCTION_IMPL(Sleep)
|
||||
args.buf = bp;
|
||||
args.buflen = len;
|
||||
JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_sleep(this->_session, ms, (switch_bool_t)sync, &args));
|
||||
info.GetReturnValue().Set(cb_state.ret);
|
||||
info.GetReturnValue().Set(js_local(cb_state.ret));
|
||||
|
||||
CheckHangupHook(this, &ret);
|
||||
if (!ret) JSMain::ExitScript(info.GetIsolate(), NULL);
|
||||
@@ -940,8 +940,8 @@ JS_SESSION_FUNCTION_IMPL(SetVariable)
|
||||
|
||||
if (info.Length() > 1) {
|
||||
const char *var, *val;
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
|
||||
var = js_safe_str(*str1);
|
||||
val = *str2;
|
||||
@@ -962,12 +962,12 @@ JS_SESSION_FUNCTION_IMPL(GetVariable)
|
||||
|
||||
if (info.Length() > 0) {
|
||||
const char *var, *val;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
|
||||
var = js_safe_str(*str);
|
||||
val = switch_channel_get_variable(channel, var);
|
||||
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(val)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(val)));
|
||||
} else {
|
||||
info.GetReturnValue().Set(false);
|
||||
}
|
||||
@@ -1029,29 +1029,29 @@ JS_SESSION_FUNCTION_IMPL(Speak)
|
||||
CHANNEL_MEDIA_SANITY_CHECK();
|
||||
|
||||
if (info.Length() < 3) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
return;
|
||||
}
|
||||
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
String::Utf8Value str3(info[2]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
JsUtf8Value str3(info[2]);
|
||||
tts_name = js_safe_str(*str1);
|
||||
voice_name = js_safe_str(*str2);
|
||||
text = js_safe_str(*str3);
|
||||
|
||||
if (zstr(tts_name)) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid TTS Name"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid TTS Name"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (zstr(text)) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid Text"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid Text"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->_speech && this->_speech->speaking) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Recursive call not allowed"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Recursive call not allowed"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1068,13 +1068,13 @@ JS_SESSION_FUNCTION_IMPL(Speak)
|
||||
switch_assert(this->_speech != NULL);
|
||||
if (InitSpeechEngine(tts_name, voice_name) != SWITCH_STATUS_SUCCESS) {
|
||||
this->_speech = NULL;
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot allocate speech engine!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot allocate speech engine!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[3]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[3]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
@@ -1103,7 +1103,7 @@ JS_SESSION_FUNCTION_IMPL(Speak)
|
||||
this->_speech->speaking = 0;
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(cb_state.ret);
|
||||
info.GetReturnValue().Set(js_local(cb_state.ret));
|
||||
|
||||
CheckHangupHook(this, &ret);
|
||||
if (!ret) JSMain::ExitScript(info.GetIsolate(), NULL);
|
||||
@@ -1123,34 +1123,34 @@ JS_SESSION_FUNCTION_IMPL(GetDigits)
|
||||
|
||||
if (info.Length() > 0) {
|
||||
char term;
|
||||
digits = info[0]->Int32Value();
|
||||
digits = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
|
||||
if (digits > sizeof(buf) - 1) {
|
||||
char *err = switch_mprintf("Exceeded max digits of %" SWITCH_SIZE_T_FMT, sizeof(buf) - 1);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
terminators = js_safe_str(*str);
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
timeout = info[2]->Int32Value();
|
||||
timeout = info[2]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (info.Length() > 3) {
|
||||
digit_timeout = info[3]->Int32Value();
|
||||
digit_timeout = info[3]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
if (info.Length() > 4) {
|
||||
abs_timeout = info[4]->Int32Value();
|
||||
abs_timeout = info[4]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
switch_ivr_collect_digits_count(this->_session, buf, sizeof(buf), digits, terminators.c_str(), &term, timeout, digit_timeout, abs_timeout);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buf));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), buf));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1162,7 +1162,7 @@ JS_SESSION_FUNCTION_IMPL(SetAutoHangup)
|
||||
METHOD_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
bool tf = info[0]->BooleanValue();
|
||||
bool tf = js_to_bool(info[0]);
|
||||
if (tf) {
|
||||
switch_set_flag(this, S_HUP);
|
||||
} else {
|
||||
@@ -1210,7 +1210,7 @@ JS_SESSION_FUNCTION_IMPL(GenerateXmlCdr)
|
||||
if (switch_ivr_generate_xml_cdr(this->_session, &cdr) == SWITCH_STATUS_SUCCESS) {
|
||||
char *xml_text;
|
||||
if ((xml_text = switch_xml_toxml(cdr, SWITCH_FALSE))) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), xml_text));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), xml_text));
|
||||
}
|
||||
switch_safe_free(xml_text);
|
||||
switch_xml_free(cdr);
|
||||
@@ -1260,7 +1260,7 @@ JS_SESSION_FUNCTION_IMPL(WaitForMedia)
|
||||
started = switch_micro_time_now();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
timeout = info[0]->Int32Value();
|
||||
timeout = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
if (timeout < 1000) {
|
||||
timeout = 1000;
|
||||
}
|
||||
@@ -1305,7 +1305,7 @@ JS_SESSION_FUNCTION_IMPL(WaitForAnswer)
|
||||
started = switch_micro_time_now();
|
||||
|
||||
if (info.Length() > 0) {
|
||||
timeout = info[0]->Int32Value();
|
||||
timeout = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
if (timeout < 1000) {
|
||||
timeout = 1000;
|
||||
}
|
||||
@@ -1350,10 +1350,10 @@ JS_SESSION_FUNCTION_IMPL(Detach)
|
||||
if (info.Length() > 0) {
|
||||
if (info[0]->IsInt32()) {
|
||||
int32_t i = 0;
|
||||
i = info[0]->Int32Value();
|
||||
i = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
cause = (switch_call_cause_t)i;
|
||||
} else {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *cause_name = js_safe_str(*str);
|
||||
cause = switch_channel_str2cause(cause_name);
|
||||
}
|
||||
@@ -1383,14 +1383,14 @@ JS_SESSION_FUNCTION_IMPL(Execute)
|
||||
|
||||
if (info.Length() > 0) {
|
||||
switch_application_interface_t *application_interface;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *app_name = js_safe_str(*str);
|
||||
string app_arg;
|
||||
|
||||
METHOD_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
app_arg = js_safe_str(*str2);
|
||||
}
|
||||
|
||||
@@ -1422,7 +1422,7 @@ JS_SESSION_FUNCTION_IMPL(GetEvent)
|
||||
METHOD_SANITY_CHECK();
|
||||
|
||||
if (switch_core_session_dequeue_event(this->_session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
||||
Handle<Object> Event;
|
||||
Local<Object> Event;
|
||||
FSEvent *evt;
|
||||
|
||||
if ((evt = new FSEvent(info))) {
|
||||
@@ -1443,13 +1443,13 @@ JS_SESSION_FUNCTION_IMPL(GetEvent)
|
||||
JS_SESSION_FUNCTION_IMPL(SendEvent)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
Handle<Object> Event;
|
||||
Local<Object> Event;
|
||||
FSEvent *eo;
|
||||
|
||||
METHOD_SANITY_CHECK();
|
||||
|
||||
if (info.Length() > 0 && info[0]->IsObject()) {
|
||||
Handle<Object> jso = Handle<Object>::Cast(info[0]);
|
||||
Local<Object> jso = Local<Object>::Cast(info[0]);
|
||||
|
||||
if (!jso.IsEmpty()) {
|
||||
switch_event_t **evt;
|
||||
@@ -1480,10 +1480,10 @@ JS_SESSION_FUNCTION_IMPL(Hangup)
|
||||
if (switch_channel_up(channel)) {
|
||||
if (info.Length() > 0) {
|
||||
if (info[0]->IsInt32()) {
|
||||
int32_t i = info[0]->Int32Value();
|
||||
int32_t i = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
cause = (switch_call_cause_t)i;
|
||||
} else {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *cause_name = js_safe_str(*str);
|
||||
cause = switch_channel_str2cause(cause_name);
|
||||
}
|
||||
@@ -1512,14 +1512,14 @@ JS_SESSION_GET_PROPERTY_IMPL(GetProperty)
|
||||
caller_profile = switch_channel_get_caller_profile(channel);
|
||||
}
|
||||
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
const char *prop = js_safe_str(*str);
|
||||
|
||||
if (!strcmp(prop, "cause")) {
|
||||
if (channel) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_channel_cause2str(switch_channel_get_cause(channel))));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_channel_cause2str(switch_channel_get_cause(channel))));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_channel_cause2str(this->_cause)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_channel_cause2str(this->_cause)));
|
||||
}
|
||||
} else if (!strcmp(prop, "causecode")) {
|
||||
if (channel) {
|
||||
@@ -1529,66 +1529,66 @@ JS_SESSION_GET_PROPERTY_IMPL(GetProperty)
|
||||
}
|
||||
} else if (!strcmp(prop, "name")) {
|
||||
if (channel) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_channel_get_name(channel)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_channel_get_name(channel)));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "uuid")) {
|
||||
if (channel) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_channel_get_uuid(channel)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_channel_get_uuid(channel)));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "state")) {
|
||||
if (channel) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_channel_state_name(switch_channel_get_state(channel))));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_channel_state_name(switch_channel_get_state(channel))));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "dialplan")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->dialplan));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->dialplan));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "caller_id_name")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->caller_id_name));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->caller_id_name));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "caller_id_num") || !strcmp(prop, "caller_id_number")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->caller_id_number));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->caller_id_number));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "network_addr") || !strcasecmp(prop, "network_address")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->network_addr));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->network_addr));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "ani")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->ani));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->ani));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "aniii")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->aniii));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->aniii));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else if (!strcmp(prop, "destination")) {
|
||||
if (caller_profile) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), caller_profile->destination_number));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), caller_profile->destination_number));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), ""));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), ""));
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1600,7 +1600,7 @@ void *FSSession::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
switch_assert(session_obj);
|
||||
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *uuid = js_safe_str(*str);
|
||||
|
||||
if (!strchr(uuid, '/')) {
|
||||
@@ -1610,7 +1610,7 @@ void *FSSession::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
FSSession *old_obj = NULL;
|
||||
|
||||
if (info.Length() > 1 && info[1]->IsObject()) {
|
||||
old_obj = JSBase::GetInstance<FSSession>(Handle<Object>::Cast(info[1]));
|
||||
old_obj = JSBase::GetInstance<FSSession>(Local<Object>::Cast(info[1]));
|
||||
}
|
||||
if (switch_ivr_originate(old_obj ? old_obj->_session : NULL,
|
||||
&session_obj->_session, &session_obj->_cause, uuid, 60,
|
||||
@@ -1619,7 +1619,7 @@ void *FSSession::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
} else {
|
||||
/* This will return the Session object, but with no C++ instance related to it */
|
||||
/* After each call to [new Session("/chan/test")] you should check the property originateCause, which will hold a value if origination failed */
|
||||
info.This()->Set(String::NewFromUtf8(info.GetIsolate(), "originateCause"), String::NewFromUtf8(info.GetIsolate(), switch_channel_cause2str(session_obj->_cause)));
|
||||
js_obj_set(info.This(), js_new_string(info.GetIsolate(), "originateCause"), js_new_string(info.GetIsolate(), switch_channel_cause2str(session_obj->_cause)));
|
||||
delete session_obj;
|
||||
return NULL;
|
||||
}
|
||||
@@ -1637,8 +1637,8 @@ JS_SESSION_FUNCTION_IMPL(SetCallerdata)
|
||||
if (info.Length() > 1) {
|
||||
const char *var, *val;
|
||||
char **toset = NULL;
|
||||
String::Utf8Value str1(info[0]);
|
||||
String::Utf8Value str2(info[1]);
|
||||
JsUtf8Value str1(info[0]);
|
||||
JsUtf8Value str2(info[1]);
|
||||
var = js_safe_str(*str1);
|
||||
val = js_safe_str(*str2);
|
||||
|
||||
@@ -1682,12 +1682,12 @@ JS_SESSION_FUNCTION_IMPL(Originate)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This method is deprecated, please use new Session(\"<dial string>\", a_leg) \n");
|
||||
|
||||
if (this->_session) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "cannot call this method on an initialized session"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "cannot call this method on an initialized session"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
Handle<Object> session_obj;
|
||||
Local<Object> session_obj;
|
||||
switch_core_session_t *session = NULL, *peer_session = NULL;
|
||||
switch_caller_profile_t *caller_profile = NULL, *orig_caller_profile = NULL;
|
||||
string dest;
|
||||
@@ -1707,17 +1707,17 @@ JS_SESSION_FUNCTION_IMPL(Originate)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (info[0]->IsObject()) {
|
||||
session_obj = Handle<Object>::Cast(info[0]);
|
||||
session_obj = Local<Object>::Cast(info[0]);
|
||||
FSSession *old_obj = NULL;
|
||||
if (!session_obj.IsEmpty() && (old_obj = JSBase::GetInstance<FSSession>(session_obj))) {
|
||||
|
||||
if (old_obj == this) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Supplied a_leg session is the same as our session"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Supplied a_leg session is the same as our session"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!old_obj->_session) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Supplied a_leg session is not initilaized!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Supplied a_leg session is not initilaized!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1751,7 +1751,7 @@ JS_SESSION_FUNCTION_IMPL(Originate)
|
||||
if (!zstr(this->_username) && zstr(username))
|
||||
username = this->_username;
|
||||
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
dest = js_safe_str(*str);
|
||||
|
||||
if (!dest.c_str() || !strchr(dest.c_str(), '/')) {
|
||||
@@ -1760,7 +1760,7 @@ JS_SESSION_FUNCTION_IMPL(Originate)
|
||||
}
|
||||
|
||||
if (info.Length() > 2) {
|
||||
String::Utf8Value strTmp(info[2]);
|
||||
JsUtf8Value strTmp(info[2]);
|
||||
tmp = *strTmp;
|
||||
if (!zstr(tmp)) {
|
||||
to = tmp;
|
||||
@@ -1769,7 +1769,7 @@ JS_SESSION_FUNCTION_IMPL(Originate)
|
||||
|
||||
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Could not create new pool"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Could not create new pool"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1796,7 +1796,7 @@ JS_SESSION_FUNCTION_IMPL(Bridge)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
FSSession *jss_b = NULL;
|
||||
Handle<Object> obj_b;
|
||||
Local<Object> obj_b;
|
||||
void *bp = NULL;
|
||||
switch_input_callback_function_t dtmf_func = NULL;
|
||||
FSInputCallbackState cb_state;
|
||||
@@ -1805,27 +1805,27 @@ JS_SESSION_FUNCTION_IMPL(Bridge)
|
||||
|
||||
if (info.Length() > 0) {
|
||||
if (info[0]->IsObject()) {
|
||||
obj_b = Handle<Object>::Cast(info[0]);
|
||||
obj_b = Local<Object>::Cast(info[0]);
|
||||
|
||||
if (!(jss_b = JSBase::GetInstance<FSSession>(obj_b))) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot find session B"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot find session B"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!_session) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "session A is not ready!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "session A is not ready!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(jss_b && jss_b->_session)) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "session B is not ready!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "session B is not ready!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[1]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
cb_state.function.Reset(info.GetIsolate(), func);
|
||||
|
||||
@@ -76,7 +76,7 @@ void *FSSocket::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
if (ret != SWITCH_STATUS_SUCCESS) {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
char *err = switch_mprintf("Failed to create socket, reason: %d", ret);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return NULL;
|
||||
}
|
||||
@@ -91,19 +91,19 @@ void *FSSocket::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
JS_SOCKET_FUNCTION_IMPL(Connect)
|
||||
{
|
||||
if (info.Length() == 2) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *host = js_safe_str(*str);
|
||||
int32_t port;
|
||||
switch_sockaddr_t *addr;
|
||||
switch_status_t ret;
|
||||
|
||||
port = info[1]->Int32Value();
|
||||
port = info[1]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
|
||||
/* Recreate socket if it has been closed */
|
||||
if (!this->_socket) {
|
||||
if ((ret = switch_socket_create(&this->_socket, AF_INET, SOCK_STREAM, SWITCH_PROTO_TCP, this->_pool)) != SWITCH_STATUS_SUCCESS) {
|
||||
char *err = switch_mprintf("Failed to create socket, reason: %d", ret);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ JS_SOCKET_FUNCTION_IMPL(Connect)
|
||||
|
||||
if (ret != SWITCH_STATUS_SUCCESS) {
|
||||
char *err = switch_mprintf("switch_sockaddr_info_get failed: %d", ret);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), err));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), err));
|
||||
free(err);
|
||||
return;
|
||||
}
|
||||
@@ -132,13 +132,13 @@ JS_SOCKET_FUNCTION_IMPL(Connect)
|
||||
JS_SOCKET_FUNCTION_IMPL(Send)
|
||||
{
|
||||
if (!this->_socket) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Socket is not active"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Socket is not active"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() == 1) {
|
||||
switch_status_t ret;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
const char *buffer = js_safe_str(*str);
|
||||
switch_size_t len = str.length(); // binary safe version of strlen()
|
||||
ret = switch_socket_send(this->_socket, buffer, &len);
|
||||
@@ -156,7 +156,7 @@ JS_SOCKET_FUNCTION_IMPL(Send)
|
||||
JS_SOCKET_FUNCTION_IMPL(ReadBytes)
|
||||
{
|
||||
if (!this->_socket) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Socket is not active"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Socket is not active"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ JS_SOCKET_FUNCTION_IMPL(ReadBytes)
|
||||
switch_status_t ret;
|
||||
switch_size_t len;
|
||||
|
||||
bytes_to_read = info[0]->Int32Value();
|
||||
bytes_to_read = info[0]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
len = (switch_size_t) bytes_to_read;
|
||||
|
||||
if (this->_buffer_size < len) {
|
||||
@@ -180,7 +180,7 @@ JS_SOCKET_FUNCTION_IMPL(ReadBytes)
|
||||
return;
|
||||
} else {
|
||||
this->_read_buffer[len] = 0;
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(this->_read_buffer)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(this->_read_buffer)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -198,12 +198,12 @@ JS_SOCKET_FUNCTION_IMPL(Read)
|
||||
char tempbuf[2];
|
||||
|
||||
if (!this->_socket) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Socket is not active"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Socket is not active"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.Length() == 1) {
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
delimiter = js_safe_str(*str);
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ JS_SOCKET_FUNCTION_IMPL(Read)
|
||||
info.GetReturnValue().Set(false);
|
||||
} else {
|
||||
this->_read_buffer[total_length] = 0;
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(this->_read_buffer)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(this->_read_buffer)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,10 +254,10 @@ JS_SOCKET_FUNCTION_IMPL(Close)
|
||||
JS_SOCKET_GET_PROPERTY_IMPL(GetProperty)
|
||||
{
|
||||
HandleScope handle_scope(info.GetIsolate());
|
||||
String::Utf8Value str(property);
|
||||
JsUtf8Value str(property);
|
||||
|
||||
if (!this->_socket) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Socket is not active"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Socket is not active"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -268,9 +268,9 @@ JS_SOCKET_GET_PROPERTY_IMPL(GetProperty)
|
||||
switch_socket_addr_get(&sa, SWITCH_TRUE, this->_socket);
|
||||
|
||||
if (sa && switch_get_addr(tmp, sizeof(tmp), sa) && !zstr(tmp)) {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), tmp));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), tmp));
|
||||
} else {
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), "unknown"));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), "unknown"));
|
||||
}
|
||||
} else if (!strcmp(js_safe_str(*str), "port")) {
|
||||
switch_sockaddr_t *sa = NULL;
|
||||
@@ -289,18 +289,18 @@ JS_SOCKET_GET_PROPERTY_IMPL(GetProperty)
|
||||
|
||||
info.GetReturnValue().Set(Int32::New(info.GetIsolate(), (int32_t)timeout));
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
JS_SOCKET_SET_PROPERTY_IMPL(SetPropertyTimeOut)
|
||||
{
|
||||
if (!this->_socket) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Socket is not active"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Socket is not active"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch_socket_timeout_set(this->_socket, value->Int32Value());
|
||||
switch_socket_timeout_set(this->_socket, value->Int32Value(js_current_context()).FromMaybe(0));
|
||||
}
|
||||
|
||||
static const js_function_t socket_methods[] = {
|
||||
|
||||
@@ -103,24 +103,24 @@ void *FSTeleTone::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
memset(&read_impl, 0, sizeof(read_impl));
|
||||
|
||||
if (info.Length() > 0 && info[0]->IsObject()) {
|
||||
Handle<Object> session_obj(Handle<Object>::Cast(info[0]));
|
||||
Local<Object> session_obj(Local<Object>::Cast(info[0]));
|
||||
|
||||
if (!session_obj.IsEmpty()) {
|
||||
if (!(jss = JSBase::GetInstance<FSSession>(session_obj)) || !jss->GetSession()) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot Find Session [1]"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot Find Session [1]"));
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot Find Session [2]"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot Find Session [2]"));
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Missing Session Arg"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Missing Session Arg"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
timer_name = js_safe_str(*str);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ void *FSTeleTone::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
|
||||
if (!(tto = new FSTeleTone(info))) {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Memory Error"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Memory Error"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ void *FSTeleTone::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
} else {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
delete tto;
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Raw codec activation failed"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Raw codec activation failed"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ JS_TELETONE_FUNCTION_IMPL(AddTone)
|
||||
int x;
|
||||
int nmax = info.Length();
|
||||
const char *map_str;
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
map_str = js_safe_str(*str);
|
||||
|
||||
if ( TELETONE_MAX_TONES < nmax ) {
|
||||
@@ -182,7 +182,7 @@ JS_TELETONE_FUNCTION_IMPL(AddTone)
|
||||
}
|
||||
|
||||
for (x = 1; x < nmax; x++) {
|
||||
String::Utf8Value fval(info[x]);
|
||||
JsUtf8Value fval(info[x]);
|
||||
if (*fval) {
|
||||
_ts.TONES[(int) *map_str].freqs[x - 1] = strtod(*fval, NULL);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ JS_TELETONE_FUNCTION_IMPL(AddTone)
|
||||
return;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
|
||||
JS_TELETONE_FUNCTION_IMPL(OnDTMF)
|
||||
@@ -203,7 +203,7 @@ JS_TELETONE_FUNCTION_IMPL(OnDTMF)
|
||||
info.GetReturnValue().Set(false);
|
||||
|
||||
if (info.Length() > 0) {
|
||||
Handle<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[0]);
|
||||
Local<Function> func = JSBase::GetFunctionFromArg(info.GetIsolate(), info[0]);
|
||||
|
||||
if (!func.IsEmpty()) {
|
||||
_function.Reset(info.GetIsolate(), func);
|
||||
@@ -229,8 +229,8 @@ JS_TELETONE_FUNCTION_IMPL(Generate)
|
||||
switch_channel_t *channel;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
if (!info[1]->IsInt32() || !(loops = info[1]->Int32Value())) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Cannot get second argument (should be int)"));
|
||||
if (!info[1]->IsInt32() || !(loops = info[1]->Int32Value(js_current_context()).FromMaybe(0))) {
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Cannot get second argument (should be int)"));
|
||||
return;
|
||||
}
|
||||
loops--;
|
||||
@@ -243,7 +243,7 @@ JS_TELETONE_FUNCTION_IMPL(Generate)
|
||||
_ts.debug = 1;
|
||||
_ts.debug_stream = switch_core_get_console();
|
||||
|
||||
String::Utf8Value str(info[0]);
|
||||
JsUtf8Value str(info[0]);
|
||||
script = js_safe_str(*str);
|
||||
teletone_run(&_ts, script);
|
||||
|
||||
@@ -270,19 +270,19 @@ JS_TELETONE_FUNCTION_IMPL(Generate)
|
||||
if (switch_channel_has_dtmf(channel)) {
|
||||
HandleScope hs(info.GetIsolate());
|
||||
uint32_t aargc = 0;
|
||||
Handle<Value> aargv[4];
|
||||
Local<Value> aargv[4];
|
||||
|
||||
switch_channel_dequeue_dtmf_string(channel, dtmf, sizeof(dtmf));
|
||||
aargv[aargc++] = String::NewFromUtf8(info.GetIsolate(), dtmf);
|
||||
aargv[aargc++] = js_new_string(info.GetIsolate(), dtmf);
|
||||
|
||||
if (!_arg.IsEmpty()) {
|
||||
aargv[aargc++] = Local<Value>::New(info.GetIsolate(), _arg);
|
||||
}
|
||||
|
||||
Handle<Function> func = Local<Function>::New(info.GetIsolate(), _function);
|
||||
Handle<Value> res = func->Call(info.GetIsolate()->GetCurrentContext()->Global(), aargc, aargv);
|
||||
Local<Function> func = Local<Function>::New(info.GetIsolate(), _function);
|
||||
Local<Value> res = js_call(func, info.GetIsolate()->GetCurrentContext()->Global(), aargc, aargv);
|
||||
|
||||
String::Utf8Value tmp(res);
|
||||
JsUtf8Value tmp(res);
|
||||
ret = js_safe_str(*tmp);
|
||||
|
||||
if (strcmp(ret, "true") && strcmp(ret, "undefined")) {
|
||||
@@ -324,12 +324,12 @@ JS_TELETONE_FUNCTION_IMPL(Generate)
|
||||
return;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
|
||||
JS_TELETONE_GET_PROPERTY_IMPL(GetNameProperty)
|
||||
{
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), "TeleTone"));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), "TeleTone"));
|
||||
}
|
||||
|
||||
static const js_function_t teletone_methods[] = {
|
||||
|
||||
@@ -90,7 +90,7 @@ void FSXML::InitRootObject()
|
||||
|
||||
void *FSXML::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
{
|
||||
String::Utf8Value data(info[0]);
|
||||
JsUtf8Value data(info[0]);
|
||||
switch_xml_t xml;
|
||||
|
||||
if (*data && (xml = switch_xml_parse_str_dynamic(*data, SWITCH_TRUE))) {
|
||||
@@ -100,7 +100,7 @@ void *FSXML::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
return obj;
|
||||
}
|
||||
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad arguments!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Bad arguments!"));
|
||||
return NULL;
|
||||
/*
|
||||
var xml = new XML(XML_FS_CONF, fs_config_name_string);
|
||||
@@ -109,7 +109,7 @@ void *FSXML::Construct(const v8::FunctionCallbackInfo<Value>& info)
|
||||
*/
|
||||
}
|
||||
|
||||
Handle<Value> FSXML::GetJSObjFromXMLObj(const switch_xml_t xml, const v8::FunctionCallbackInfo<Value>& info)
|
||||
Local<Value> FSXML::GetJSObjFromXMLObj(const switch_xml_t xml, const v8::FunctionCallbackInfo<Value>& info)
|
||||
{
|
||||
FSXML *newObj, *rootObj = NULL;
|
||||
|
||||
@@ -121,7 +121,7 @@ Handle<Value> FSXML::GetJSObjFromXMLObj(const switch_xml_t xml, const v8::Functi
|
||||
|
||||
if (!rootObj) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find XML root node\n");
|
||||
return Handle<Value>();
|
||||
return Local<Value>();
|
||||
}
|
||||
|
||||
/* Try to find an existing object in the hash */
|
||||
@@ -146,7 +146,7 @@ Handle<Value> FSXML::GetJSObjFromXMLObj(const switch_xml_t xml, const v8::Functi
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create new object - memory error?\n");
|
||||
return Handle<Value>();
|
||||
return Local<Value>();
|
||||
}
|
||||
|
||||
void FSXML::StoreObjectInHash(switch_xml_t xml, FSXML *obj)
|
||||
@@ -218,17 +218,17 @@ void FSXML::DestroyHash()
|
||||
JS_XML_FUNCTION_IMPL(GetChild)
|
||||
{
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value name(info[0]);
|
||||
JsUtf8Value name(info[0]);
|
||||
string attr_name, attr_value;
|
||||
switch_xml_t xml = NULL;
|
||||
|
||||
/* Check if attribute name/value was provided as well */
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
attr_name = js_safe_str(*str);
|
||||
|
||||
if (info.Length() > 2) {
|
||||
String::Utf8Value str2(info[2]);
|
||||
JsUtf8Value str2(info[2]);
|
||||
attr_value = js_safe_str(*str2);
|
||||
}
|
||||
}
|
||||
@@ -242,10 +242,10 @@ JS_XML_FUNCTION_IMPL(GetChild)
|
||||
|
||||
/* Return the JS object */
|
||||
if (xml) {
|
||||
Handle<Value> jsObj = GetJSObjFromXMLObj(xml, info);
|
||||
Local<Value> jsObj = GetJSObjFromXMLObj(xml, info);
|
||||
|
||||
if (jsObj.IsEmpty()) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed!"));
|
||||
} else {
|
||||
info.GetReturnValue().Set(jsObj);
|
||||
}
|
||||
@@ -253,19 +253,19 @@ JS_XML_FUNCTION_IMPL(GetChild)
|
||||
info.GetReturnValue().Set(Null(info.GetIsolate()));
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
JS_XML_FUNCTION_IMPL(AddChild)
|
||||
{
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value name(info[0]);
|
||||
JsUtf8Value name(info[0]);
|
||||
switch_xml_t xml;
|
||||
int offset = 0;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
offset = info[1]->Int32Value();
|
||||
offset = info[1]->Int32Value(js_current_context()).FromMaybe(0);
|
||||
}
|
||||
|
||||
/* Add new child */
|
||||
@@ -273,18 +273,18 @@ JS_XML_FUNCTION_IMPL(AddChild)
|
||||
|
||||
/* Return the JS object */
|
||||
if (xml) {
|
||||
Handle<Value> jsObj = GetJSObjFromXMLObj(xml, info);
|
||||
Local<Value> jsObj = GetJSObjFromXMLObj(xml, info);
|
||||
|
||||
if (jsObj.IsEmpty()) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed!"));
|
||||
} else {
|
||||
info.GetReturnValue().Set(jsObj);
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "XML error"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "XML error"));
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,10 +297,10 @@ JS_XML_FUNCTION_IMPL(Next)
|
||||
|
||||
/* Return the JS object */
|
||||
if (xml) {
|
||||
Handle<Value> jsObj = GetJSObjFromXMLObj(xml, info);
|
||||
Local<Value> jsObj = GetJSObjFromXMLObj(xml, info);
|
||||
|
||||
if (jsObj.IsEmpty()) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Failed!"));
|
||||
} else {
|
||||
info.GetReturnValue().Set(jsObj);
|
||||
}
|
||||
@@ -312,21 +312,21 @@ JS_XML_FUNCTION_IMPL(Next)
|
||||
JS_XML_FUNCTION_IMPL(GetAttribute)
|
||||
{
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value name(info[0]);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), switch_xml_attr_soft(_xml, js_safe_str(*name))));
|
||||
JsUtf8Value name(info[0]);
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), switch_xml_attr_soft(_xml, js_safe_str(*name))));
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
JS_XML_FUNCTION_IMPL(SetAttribute)
|
||||
{
|
||||
if (info.Length() > 0) {
|
||||
String::Utf8Value name(info[0]);
|
||||
JsUtf8Value name(info[0]);
|
||||
string val;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
String::Utf8Value str(info[1]);
|
||||
JsUtf8Value str(info[1]);
|
||||
val = js_safe_str(*str);
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ JS_XML_FUNCTION_IMPL(SetAttribute)
|
||||
info.GetReturnValue().Set(false);
|
||||
}
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "Invalid arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ JS_XML_IMPL_STATIC(Remove)
|
||||
}
|
||||
delete obj;
|
||||
} else {
|
||||
String::Utf8Value str(info.Holder());
|
||||
JsUtf8Value str(info.Holder());
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No valid internal data available for %s when calling FSXML::Remove()\n", *str ? *str : "[unknown]");
|
||||
}
|
||||
}
|
||||
@@ -373,39 +373,39 @@ JS_XML_FUNCTION_IMPL(Copy)
|
||||
obj->RegisterInstance(info.GetIsolate(), "", true);
|
||||
info.GetReturnValue().Set(obj->GetJavaScriptObject());
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "XML error"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "XML error"));
|
||||
}
|
||||
}
|
||||
|
||||
JS_XML_FUNCTION_IMPL(Serialize)
|
||||
{
|
||||
char *data = switch_xml_toxml(_xml, SWITCH_FALSE);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(data)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(data)));
|
||||
switch_safe_free(data);
|
||||
}
|
||||
|
||||
JS_XML_GET_PROPERTY_IMPL(GetNameProperty)
|
||||
{
|
||||
const char *data = switch_xml_name(_xml);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(data)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(data)));
|
||||
}
|
||||
|
||||
JS_XML_GET_PROPERTY_IMPL(GetDataProperty)
|
||||
{
|
||||
const char *data = switch_xml_txt(_xml);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(data)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(data)));
|
||||
}
|
||||
|
||||
JS_XML_SET_PROPERTY_IMPL(SetDataProperty)
|
||||
{
|
||||
String::Utf8Value str(value);
|
||||
JsUtf8Value str(value);
|
||||
switch_xml_set_txt_d(_xml, js_safe_str(*str));
|
||||
}
|
||||
|
||||
JS_XML_GET_PROPERTY_IMPL(GetErrorProperty)
|
||||
{
|
||||
const char *data = switch_xml_error(_xml);
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(data)));
|
||||
info.GetReturnValue().Set(js_new_string(info.GetIsolate(), js_safe_str(data)));
|
||||
}
|
||||
|
||||
static const js_function_t xml_methods[] = {
|
||||
|
||||
@@ -69,8 +69,14 @@ JSBase::~JSBase(void)
|
||||
}
|
||||
|
||||
/* If the object is still alive inside V8, set the internal field to NULL. But only if we're actually inside a JS context */
|
||||
if (!persistentHandle->IsNearDeath() && !GetIsolate()->GetCurrentContext().IsEmpty() && (!js || !js->GetForcedTermination())) {
|
||||
Handle<Object> jsObj = GetJavaScriptObject();
|
||||
if (
|
||||
#if !V8FS_NEW_API
|
||||
/* IsNearDeath() was removed from V8; on the new API the weak callback
|
||||
* already guarantees we are not racing the collector here. */
|
||||
!persistentHandle->IsNearDeath() &&
|
||||
#endif
|
||||
!GetIsolate()->GetCurrentContext().IsEmpty() && (!js || !js->GetForcedTermination())) {
|
||||
Local<Object> jsObj = GetJavaScriptObject();
|
||||
jsObj->SetInternalField(0, Null(GetIsolate()));
|
||||
}
|
||||
|
||||
@@ -80,13 +86,13 @@ JSBase::~JSBase(void)
|
||||
delete persistentHandle;
|
||||
}
|
||||
|
||||
Handle<Object> JSBase::GetJavaScriptObject()
|
||||
Local<Object> JSBase::GetJavaScriptObject()
|
||||
{
|
||||
/* Returns the javascript object related to this C++ instance */
|
||||
return Local<Object>::New(GetIsolate(), *persistentHandle);
|
||||
}
|
||||
|
||||
void JSBase::AddInstance(Isolate *isolate, const Handle<Object>& handle, const Handle<External>& object, bool autoDestroy)
|
||||
void JSBase::AddInstance(Isolate *isolate, const Local<Object>& handle, const Local<External>& object, bool autoDestroy)
|
||||
{
|
||||
// Get the actual C++ class pointer
|
||||
JSBase *obj = static_cast<JSBase*>(object->Value());
|
||||
@@ -107,7 +113,11 @@ void JSBase::AddInstance(Isolate *isolate, const Handle<Object>& handle, const H
|
||||
#else
|
||||
obj->persistentHandle->SetWeak<JSBase>(obj, WeakCallback);
|
||||
#endif
|
||||
#if !V8FS_NEW_API
|
||||
/* MarkIndependent() was removed from V8; independence is now the default
|
||||
* for weak handles, so this call is no longer needed on the new API. */
|
||||
obj->persistentHandle->MarkIndependent();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5
|
||||
@@ -138,25 +148,25 @@ void JSBase::WeakCallback(const WeakCallbackData<Object, JSBase>& data)
|
||||
|
||||
void JSBase::CreateInstance(const v8::FunctionCallbackInfo<Value>& args)
|
||||
{
|
||||
Handle<External> external;
|
||||
Local<External> external;
|
||||
bool autoDestroy = true;
|
||||
bool constructorFailed = false;
|
||||
|
||||
if (!args.IsConstructCall()) {
|
||||
args.GetIsolate()->ThrowException(String::NewFromUtf8(args.GetIsolate(), "Seems you forgot the 'new' operator."));
|
||||
args.GetIsolate()->ThrowException(js_new_string(args.GetIsolate(), "Seems you forgot the 'new' operator."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0]->IsExternal()) {
|
||||
// The argument is an existing object, just use that.
|
||||
external = Handle<External>::Cast(args[0]);
|
||||
autoDestroy = args[1]->BooleanValue();
|
||||
external = Local<External>::Cast(args[0]);
|
||||
autoDestroy = js_to_bool(args[1]);
|
||||
} else {
|
||||
// Create a new C++ instance
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5
|
||||
Handle<External> ex = Handle<External>::Cast(args.Data());
|
||||
Local<External> ex = Local<External>::Cast(args.Data());
|
||||
#else
|
||||
Handle<External> ex = Handle<External>::Cast(args.Callee()->GetHiddenValue(String::NewFromUtf8(args.GetIsolate(), "constructor_method")));
|
||||
Local<External> ex = Local<External>::Cast(args.Callee()->GetHiddenValue(js_new_string(args.GetIsolate(), "constructor_method")));
|
||||
#endif
|
||||
|
||||
if (ex->Value()) {
|
||||
@@ -178,7 +188,7 @@ void JSBase::CreateInstance(const v8::FunctionCallbackInfo<Value>& args)
|
||||
// Return the newly created object
|
||||
args.GetReturnValue().Set(args.This());
|
||||
} else if (!constructorFailed) {
|
||||
args.GetIsolate()->ThrowException(String::NewFromUtf8(args.GetIsolate(), "This class cannot be created from javascript."));
|
||||
args.GetIsolate()->ThrowException(js_new_string(args.GetIsolate(), "This class cannot be created from javascript."));
|
||||
} else {
|
||||
/* Use whatever was set from the constructor */
|
||||
}
|
||||
@@ -187,13 +197,13 @@ void JSBase::CreateInstance(const v8::FunctionCallbackInfo<Value>& args)
|
||||
void JSBase::Register(Isolate *isolate, const js_class_definition_t *desc)
|
||||
{
|
||||
// Get the context's global scope (that's where we'll put the constructor)
|
||||
Handle<Object> global = isolate->GetCurrentContext()->Global();
|
||||
Local<Object> global = isolate->GetCurrentContext()->Global();
|
||||
|
||||
Local<External> data = External::New(isolate, (void *)desc->constructor);
|
||||
|
||||
// Create function template for our constructor it will call the JSBase::createInstance method
|
||||
Handle<FunctionTemplate> function = FunctionTemplate::New(isolate, JSBase::CreateInstance, data);
|
||||
function->SetClassName(String::NewFromUtf8(isolate, desc->name));
|
||||
Local<FunctionTemplate> function = FunctionTemplate::New(isolate, JSBase::CreateInstance, data);
|
||||
function->SetClassName(js_new_string(isolate, desc->name));
|
||||
|
||||
// Make room for saving the C++ object reference somewhere
|
||||
function->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
@@ -201,39 +211,39 @@ void JSBase::Register(Isolate *isolate, const js_class_definition_t *desc)
|
||||
// Add methods to the object
|
||||
for (int i = 0;; i++) {
|
||||
if (!desc->functions[i].func) break;
|
||||
function->InstanceTemplate()->Set(String::NewFromUtf8(isolate, desc->functions[i].name), FunctionTemplate::New(isolate, desc->functions[i].func));
|
||||
function->InstanceTemplate()->Set(js_new_string(isolate, desc->functions[i].name), FunctionTemplate::New(isolate, desc->functions[i].func));
|
||||
}
|
||||
|
||||
// Add properties to the object
|
||||
for (int i = 0;; i++) {
|
||||
if (!desc->properties[i].get) break;
|
||||
function->InstanceTemplate()->SetAccessor(String::NewFromUtf8(isolate, desc->properties[i].name), desc->properties[i].get, desc->properties[i].set);
|
||||
function->InstanceTemplate()->SetAccessor(js_new_string(isolate, desc->properties[i].name), desc->properties[i].get, desc->properties[i].set);
|
||||
}
|
||||
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5
|
||||
#else
|
||||
function->GetFunction()->SetHiddenValue(String::NewFromUtf8(isolate, "constructor_method"), External::New(isolate, (void *)desc->constructor));
|
||||
function->GetFunction(js_current_context()).ToLocalChecked()->SetHiddenValue(js_new_string(isolate, "constructor_method"), External::New(isolate, (void *)desc->constructor));
|
||||
#endif
|
||||
|
||||
// Set the function in the global scope, to make it available
|
||||
global->Set(v8::String::NewFromUtf8(isolate, desc->name), function->GetFunction());
|
||||
js_obj_set(global, js_new_string(isolate, desc->name), function->GetFunction(js_current_context()).ToLocalChecked());
|
||||
}
|
||||
|
||||
void JSBase::RegisterInstance(Isolate *isolate, string name, bool autoDestroy)
|
||||
{
|
||||
// Get the context's global scope (that's where we'll put the constructor)
|
||||
Local<Context> context = isolate->GetCurrentContext();
|
||||
Handle<Object> global = context->Global();
|
||||
Local<Object> global = context->Global();
|
||||
|
||||
Local<Function> func = Local<Function>::Cast(global->Get(v8::String::NewFromUtf8(isolate, this->GetJSClassName().c_str())));
|
||||
Local<Function> func = Local<Function>::Cast(js_obj_get(global, js_new_string(isolate, this->GetJSClassName().c_str())));
|
||||
|
||||
// Add the C++ instance as an argument, so it won't try to create another one.
|
||||
Handle<Value> args[] = { External::New(isolate, this), Boolean::New(isolate, autoDestroy) };
|
||||
Handle<Object> newObj = func->NewInstance(context, 2, args).ToLocalChecked();
|
||||
Local<Value> args[] = { External::New(isolate, this), Boolean::New(isolate, autoDestroy) };
|
||||
Local<Object> newObj = func->NewInstance(context, 2, args).ToLocalChecked();
|
||||
|
||||
// Add the instance to JavaScript.
|
||||
if (name.size() > 0) {
|
||||
global->Set(String::NewFromUtf8(isolate, name.c_str()), newObj);
|
||||
js_obj_set(global, js_new_string(isolate, name.c_str()), newObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,20 +262,20 @@ bool JSBase::GetAutoDestroy()
|
||||
return autoDestroy;
|
||||
}
|
||||
|
||||
Handle<Function> JSBase::GetFunctionFromArg(Isolate *isolate, const Local<Value>& arg)
|
||||
Local<Function> JSBase::GetFunctionFromArg(Isolate *isolate, const Local<Value>& arg)
|
||||
{
|
||||
Handle<Function> func;
|
||||
Local<Function> func;
|
||||
|
||||
if (!arg.IsEmpty() && arg->IsFunction()) {
|
||||
// Cast the argument directly to a function
|
||||
func = Handle<Function>::Cast(arg);
|
||||
func = Local<Function>::Cast(arg);
|
||||
} else if (!arg.IsEmpty() && arg->IsString()) {
|
||||
Handle<String> tmp = Handle<String>::Cast(arg);
|
||||
Local<String> tmp = Local<String>::Cast(arg);
|
||||
if (!tmp.IsEmpty() && *tmp) {
|
||||
// Fetch the actual function pointer from the global context (by function name)
|
||||
Handle<Value> val = isolate->GetCurrentContext()->Global()->Get(tmp);
|
||||
Local<Value> val = js_obj_get(isolate->GetCurrentContext()->Global(), tmp);
|
||||
if (!val.IsEmpty() && val->IsFunction()) {
|
||||
func = Handle<Function>::Cast(val);
|
||||
func = Local<Function>::Cast(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,13 +283,13 @@ Handle<Function> JSBase::GetFunctionFromArg(Isolate *isolate, const Local<Value>
|
||||
if (!func.IsEmpty() && func->IsFunction()) {
|
||||
return func;
|
||||
} else {
|
||||
return Handle<Function>();
|
||||
return Local<Function>();
|
||||
}
|
||||
}
|
||||
|
||||
void JSBase::DefaultSetProperty(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
info.GetIsolate()->ThrowException(v8::String::NewFromUtf8(info.GetIsolate(), "this property cannot be changed!"));
|
||||
info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "this property cannot be changed!"));
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
|
||||
@@ -179,25 +179,25 @@ JSMain::~JSMain(void)
|
||||
const string JSMain::GetExceptionInfo(Isolate* isolate, TryCatch* try_catch)
|
||||
{
|
||||
HandleScope handle_scope(isolate);
|
||||
String::Utf8Value exception(try_catch->Exception());
|
||||
JsUtf8Value exception(try_catch->Exception());
|
||||
const char *exception_string = js_safe_str(*exception);
|
||||
Handle<Message> message = try_catch->Message();
|
||||
Local<Message> message = try_catch->Message();
|
||||
string res;
|
||||
|
||||
if (message.IsEmpty()) {
|
||||
// V8 didn't provide any extra information about this error; just return the exception.
|
||||
res = exception_string;
|
||||
} else {
|
||||
String::Utf8Value filename(message->GetScriptResourceName());
|
||||
JsUtf8Value filename(message->GetScriptResourceName());
|
||||
const char *filename_string = js_safe_str(*filename);
|
||||
int linenum = message->GetLineNumber();
|
||||
int linenum = message->GetLineNumber(js_current_context()).FromMaybe(0);
|
||||
|
||||
ostringstream ss;
|
||||
|
||||
ss << filename_string << ":" << linenum << ": " << exception_string << "\r\n";
|
||||
|
||||
// Print line of source code.
|
||||
String::Utf8Value sourceline(message->GetSourceLine());
|
||||
JsUtf8Value sourceline(message->GetSourceLine(js_current_context()).ToLocalChecked());
|
||||
const char *sourceline_string = js_safe_str(*sourceline);
|
||||
|
||||
ss << sourceline_string << "\r\n";
|
||||
@@ -225,7 +225,7 @@ void JSMain::Include(const v8::FunctionCallbackInfo<Value>& args)
|
||||
{
|
||||
for (int i = 0; i < args.Length(); i++) {
|
||||
HandleScope handle_scope(args.GetIsolate());
|
||||
String::Utf8Value str(args[i]);
|
||||
JsUtf8Value str(args[i]);
|
||||
|
||||
// load_file loads the file with this name into a string
|
||||
string js_file = LoadFileToString(js_safe_str(*str));
|
||||
@@ -239,12 +239,12 @@ void JSMain::Include(const v8::FunctionCallbackInfo<Value>& args)
|
||||
args.GetReturnValue().Set(false);
|
||||
}
|
||||
else {
|
||||
args.GetReturnValue().Set(script.ToLocalChecked()->Run());
|
||||
args.GetReturnValue().Set(js_run_script(script.ToLocalChecked()));
|
||||
}
|
||||
#else
|
||||
Handle<String> source = String::NewFromUtf8(args.GetIsolate(), js_file.c_str());
|
||||
Handle<Script> script = Script::Compile(source, args[i]);
|
||||
args.GetReturnValue().Set(script->Run());
|
||||
Local<String> source = js_new_string(args.GetIsolate(), js_file.c_str());
|
||||
Local<Script> script = Script::Compile(source, args[i]);
|
||||
args.GetReturnValue().Set(js_run_script(script));
|
||||
#endif
|
||||
|
||||
return;
|
||||
@@ -257,7 +257,7 @@ void JSMain::Include(const v8::FunctionCallbackInfo<Value>& args)
|
||||
void JSMain::Log(const v8::FunctionCallbackInfo<Value>& args)
|
||||
{
|
||||
HandleScope handle_scope(args.GetIsolate());
|
||||
String::Utf8Value str(args[0]);
|
||||
JsUtf8Value str(args[0]);
|
||||
|
||||
printf("%s\r\n", js_safe_str(*str));
|
||||
|
||||
@@ -287,14 +287,14 @@ const string JSMain::ExecuteString(const string& scriptData, const string& fileN
|
||||
|
||||
isolate->SetData(0, this);
|
||||
|
||||
Handle<ObjectTemplate> global = ObjectTemplate::New(isolate);
|
||||
global->Set(String::NewFromUtf8(isolate, "include"), FunctionTemplate::New(isolate, Include));
|
||||
global->Set(String::NewFromUtf8(isolate, "require"), FunctionTemplate::New(isolate, Include));
|
||||
global->Set(String::NewFromUtf8(isolate, "log"), FunctionTemplate::New(isolate, Log));
|
||||
Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
|
||||
global->Set(js_new_string(isolate, "include"), FunctionTemplate::New(isolate, Include));
|
||||
global->Set(js_new_string(isolate, "require"), FunctionTemplate::New(isolate, Include));
|
||||
global->Set(js_new_string(isolate, "log"), FunctionTemplate::New(isolate, Log));
|
||||
|
||||
for (size_t i = 0; i < extenderFunctions->size(); i++) {
|
||||
js_function_t *proc = (*extenderFunctions)[i];
|
||||
global->Set(String::NewFromUtf8(isolate, proc->name), FunctionTemplate::New(isolate, proc->func));
|
||||
global->Set(js_new_string(isolate, proc->name), FunctionTemplate::New(isolate, proc->func));
|
||||
}
|
||||
|
||||
// Create a new context.
|
||||
@@ -327,8 +327,8 @@ const string JSMain::ExecuteString(const string& scriptData, const string& fileN
|
||||
LoadScript(&script, isolate, scriptData.c_str(), fileName.c_str());
|
||||
#else
|
||||
// Create a string containing the JavaScript source code.
|
||||
Handle<String> source = String::NewFromUtf8(isolate, scriptData.c_str());
|
||||
Handle<Script> script = Script::Compile(source, Local<Value>::New(isolate, String::NewFromUtf8(isolate, fileName.c_str())));
|
||||
Local<String> source = js_new_string(isolate, scriptData.c_str());
|
||||
Local<Script> script = Script::Compile(source, Local<Value>::New(isolate, js_new_string(isolate, fileName.c_str())));
|
||||
#endif
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
@@ -337,14 +337,14 @@ const string JSMain::ExecuteString(const string& scriptData, const string& fileN
|
||||
} else {
|
||||
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5
|
||||
// Run the script
|
||||
Handle<Value> result;
|
||||
Local<Value> result;
|
||||
|
||||
if (!script.IsEmpty()) {
|
||||
result = script.ToLocalChecked()->Run();
|
||||
result = js_run_script(script.ToLocalChecked());
|
||||
}
|
||||
#else
|
||||
// Run the script
|
||||
Handle<Value> result = script->Run();
|
||||
Local<Value> result = js_run_script(script);
|
||||
#endif
|
||||
if (try_catch.HasCaught()) {
|
||||
res = JSMain::GetExceptionInfo(isolate, &try_catch);
|
||||
@@ -356,7 +356,7 @@ const string JSMain::ExecuteString(const string& scriptData, const string& fileN
|
||||
}
|
||||
|
||||
// return result as string.
|
||||
String::Utf8Value ascii(result);
|
||||
JsUtf8Value ascii(result);
|
||||
if (*ascii) {
|
||||
res = *ascii;
|
||||
}
|
||||
@@ -444,9 +444,18 @@ Isolate *JSMain::GetIsolate()
|
||||
void JSMain::Initialize(v8::Platform **platform)
|
||||
{
|
||||
V8::InitializeICUDefaultLocation(SWITCH_GLOBAL_dirs.mod_dir);
|
||||
#if !V8FS_NEW_API
|
||||
/* External V8 startup data was removed; modern V8 embeds the snapshot. */
|
||||
V8::InitializeExternalStartupData(SWITCH_GLOBAL_dirs.mod_dir);
|
||||
#endif
|
||||
|
||||
#if V8FS_NEW_API
|
||||
/* CreateDefaultPlatform() was replaced by NewDefaultPlatform(), which
|
||||
* returns an owning unique_ptr; release it into our raw pointer. */
|
||||
*platform = v8::platform::NewDefaultPlatform().release();
|
||||
#else
|
||||
*platform = v8::platform::CreateDefaultPlatform();
|
||||
#endif
|
||||
V8::InitializePlatform(*platform);
|
||||
V8::Initialize();
|
||||
}
|
||||
@@ -464,7 +473,14 @@ void JSMain::Dispose()
|
||||
v8::Isolate::GetCurrent()->LowMemoryNotification();
|
||||
while (!v8::Isolate::GetCurrent()->IdleNotificationDeadline(0.500)) {}
|
||||
V8::Dispose();
|
||||
#if V8_MAJOR_VERSION >= 10
|
||||
/* ShutdownPlatform() became a deprecated alias for DisposePlatform() in
|
||||
* V8 10 and was removed in later releases (e.g. the V8 shipped by Debian
|
||||
* trixie's libnode). DisposePlatform() exists from V8 10 onwards. */
|
||||
V8::DisposePlatform();
|
||||
#else
|
||||
V8::ShutdownPlatform();
|
||||
#endif
|
||||
#else
|
||||
V8::LowMemoryNotification();
|
||||
while (!V8::IdleNotification()) {}
|
||||
@@ -595,13 +611,13 @@ char *JSMain::GetStackInfo(Isolate *isolate, int *lineNumber)
|
||||
Local<StackTrace> stFile = StackTrace::CurrentStackTrace(isolate, 1, StackTrace::kScriptName);
|
||||
|
||||
if (!stFile.IsEmpty()) {
|
||||
Local<StackFrame> sf = stFile->GetFrame(0);
|
||||
Local<StackFrame> sf = js_stack_frame(stFile, isolate, 0);
|
||||
|
||||
if (!sf.IsEmpty()) {
|
||||
Local<String> fn = sf->GetScriptName();
|
||||
|
||||
if (!fn.IsEmpty()) {
|
||||
String::Utf8Value str(fn);
|
||||
JsUtf8Value str(fn);
|
||||
|
||||
if (*str) {
|
||||
js_strdup(ret, *str); // We must dup here
|
||||
@@ -622,7 +638,7 @@ char *JSMain::GetStackInfo(Isolate *isolate, int *lineNumber)
|
||||
Local<StackTrace> stLine = StackTrace::CurrentStackTrace(isolate, 1, StackTrace::kLineNumber);
|
||||
|
||||
if (!stLine.IsEmpty()) {
|
||||
Local<StackFrame> sf = stLine->GetFrame(0);
|
||||
Local<StackFrame> sf = js_stack_frame(stLine, isolate, 0);
|
||||
|
||||
if (!sf.IsEmpty()) {
|
||||
*lineNumber = sf->GetLineNumber();
|
||||
|
||||
Reference in New Issue
Block a user