static JSValueRef set_language_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *language = NULL; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } language = arg_to_string(context, arguments[0], exception); if (!language) { return JSValueMakeNull(context); } lightdm_greeter_set_language(GREETER, language); g_free(language); return JSValueMakeNull(context); }
static JSValueRef seed_gobject_signal_connect_on_property (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) { gulong id = 0; JSObjectRef this_obj; signal_privates *privates; privates = (signal_privates *) JSObjectGetPrivate (thisObject); if (!privates) g_error ("Signal constructed with invalid parameters" "in namespace import \n"); this_obj = (JSObjectRef) seed_value_from_object (ctx, privates->object, exception); if ((argumentCount > 2) || (argumentCount == 0)) { seed_make_exception (ctx, exception, "ArgumentError", "Signal connection expected" " 1, or 2 arguments. Got " "%zd", argumentCount); return JSValueMakeNull (ctx); } if (JSValueIsNull (ctx, arguments[0]) || !JSValueIsObject (ctx, arguments[0]) || !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0])) { seed_make_exception (ctx, exception, "ArgumentError", "Signal connection requires a function" " as first argument"); return JSValueMakeNull (ctx); } if (argumentCount == 1) { id = seed_gobject_signal_connect (ctx, privates->signal_name, privates->object, (JSObjectRef) arguments[0], this_obj, NULL); } else if (argumentCount == 2) { id = seed_gobject_signal_connect (ctx, privates->signal_name, privates->object, (JSObjectRef) arguments[0], this_obj, (JSObjectRef) arguments[1]); } return seed_value_from_ulong (ctx, id, exception); }
static JSValueRef get_dirlist_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { JSObjectRef array; guint n_entries = 0; JSValueRef *args = NULL; GDir *dir; gchar *path, *fullpath; const gchar *dirent; GError *err = NULL; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } path = arg_to_string(context, arguments[0], exception); if (!path) { return JSValueMakeNull(context); } dir = g_dir_open (path, 0, &err); if (err) { _mkexception(context, exception, err->message); g_error_free(err); return JSValueMakeNull(context); } /* * Create the lis of the directory entries */ while ((dirent = g_dir_read_name (dir)) != NULL) { n_entries++; args = g_realloc (args, sizeof (JSValueRef) * (n_entries + 1)); fullpath = g_build_filename (path, dirent, NULL); /* Give theme developer full pathname */ args[(n_entries - 1)] = string_or_null (context, fullpath); g_free (fullpath); } g_dir_close (dir); array = JSObjectMakeArray (context, n_entries, args, exception); g_free (args); if (array == NULL) { return JSValueMakeNull (context); } else { return array; } }
static JSValueRef zs__ (JSContextRef js_context, JSObjectRef js_function, JSObjectRef js_this, size_t argument_count, const JSValueRef js_arguments[], JSValueRef* js_exception) { if(argument_count<=0){ return JSValueMakeNull (js_context); } const char*ret; { window___* w=reinterpret_cast<window___*>(JSObjectGetPrivate(js_function)); if(!w){ return JSValueMakeNull (js_context); } char** argv=new char*[argument_count+1]; JSStringRef* jsr=new JSStringRef[argument_count]; for(size_t i=0;i<argument_count;i++){ jsr[i]=JSValueToStringCopy(js_context, js_arguments[i], js_exception); size_t jsSize = JSStringGetMaximumUTF8CStringSize(jsr[i]); argv[i]=new char[jsSize]; JSStringGetUTF8CString(jsr[i], argv[i], jsSize); } if(!argv[0][0]){ ret=NULL; for(size_t i=1;i<argument_count;i++) cout<<argv[i]; cout<<endl; }else ret=call4__(argv[0],NULL,argument_count,(const char**)argv,1); for(size_t i=0;i<argument_count;i++){ delete argv[i]; JSStringRelease(jsr[i]); } delete jsr; delete argv; } if(!ret) return JSValueMakeNull (js_context); JSValueRef ret2; if(true_==ret||false_==ret){ ret2=JSValueMakeBoolean(js_context,true_==ret); }else{ JSStringRef ret1=JSStringCreateWithUTF8CString(ret); ret2=JSValueMakeString(js_context,ret1); JSStringRelease (ret1); } return ret2; }
JSValueRef Value::fromDynamicInner(JSContextRef ctx, const folly::dynamic& obj) { switch (obj.type()) { // For premitive types (and strings), just create and return an equivalent JSValue case folly::dynamic::Type::NULLT: return JSValueMakeNull(ctx); case folly::dynamic::Type::BOOL: return JSValueMakeBoolean(ctx, obj.getBool()); case folly::dynamic::Type::DOUBLE: return JSValueMakeNumber(ctx, obj.getDouble()); case folly::dynamic::Type::INT64: return JSValueMakeNumber(ctx, obj.asDouble()); case folly::dynamic::Type::STRING: return JSValueMakeString(ctx, String(obj.getString().c_str())); case folly::dynamic::Type::ARRAY: { // Collect JSValue for every element in the array JSValueRef vals[obj.size()]; for (size_t i = 0; i < obj.size(); ++i) { vals[i] = fromDynamicInner(ctx, obj[i]); } // Create a JSArray with the values JSValueRef arr = JSObjectMakeArray(ctx, obj.size(), vals, nullptr); return arr; } case folly::dynamic::Type::OBJECT: { // Create an empty object JSObjectRef jsObj = JSObjectMake(ctx, nullptr, nullptr); // Create a JSValue for each of the object's children and set them in the object for (auto it = obj.items().begin(); it != obj.items().end(); ++it) { JSObjectSetProperty( ctx, jsObj, String(it->first.asString().c_str()), fromDynamicInner(ctx, it->second), kJSPropertyAttributeNone, nullptr); } return jsObj; } default: // Assert not reached LOG(FATAL) << "Trying to convert a folly object of unsupported type."; return JSValueMakeNull(ctx); } }
JS4D::ValueRef JS4D::VBlobToValue( ContextRef inContext, const VBlob& inBlob, const VString& inContentType) { if (inBlob.IsNull()) return JSValueMakeNull( inContext); VJSBlobValue_Slice* blobValue = VJSBlobValue_Slice::Create( inBlob, inContentType); if (blobValue == NULL) return JSValueMakeNull( inContext); ValueRef value = VJSBlob::CreateInstance( inContext, blobValue); ReleaseRefCountable( &blobValue); return value; }
static JSValueRef seed_gobject_signal_connect_by_name (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) { GType obj_type; JSObjectRef user_data = NULL; gchar *signal_name; GObject *obj; gulong id; if (argumentCount < 2 || argumentCount > 3) { seed_make_exception (ctx, exception, "ArgumentError", "Signal connection expected" " 2 or 3 arguments. Got " "%zd", argumentCount); return JSValueMakeNull (ctx); } if (JSValueIsNull (ctx, arguments[1]) || !JSValueIsObject (ctx, arguments[1]) || !JSObjectIsFunction (ctx, (JSObjectRef) arguments[1])) { seed_make_exception (ctx, exception, "ArgumentError", "Signal connection by name " "requires a function" " as second argument"); return JSValueMakeNull (ctx); } if (argumentCount == 3) { user_data = (JSObjectRef) arguments[2]; } signal_name = seed_value_to_string (ctx, arguments[0], exception); obj = (GObject *) JSObjectGetPrivate (thisObject); obj_type = G_OBJECT_TYPE (obj); id = seed_gobject_signal_connect (ctx, signal_name, obj, (JSObjectRef) arguments[1], NULL, user_data); g_free (signal_name); return seed_value_from_ulong (ctx, id, exception); }
static JSValueRef js_cb_launcher_submit(JSContextRef context, JSObjectRef function, JSObjectRef self, size_t argc, const JSValueRef argv[], JSValueRef* exception) { if (argc != 2) return JSValueMakeNull(context); int len = JSValueToNumber(context, argv[0], NULL); JSObjectRef arr = JSValueToObject(context, argv[1], NULL); static const int CMD_LINE_SIZE = 4096; static const int CMD_ARGS_SIZE = 256; char cmd_str_buf[CMD_LINE_SIZE]; int cmd_str_buf_cur = 0; char *cmd_idx_buf[CMD_ARGS_SIZE]; if (len == 0 || len >= CMD_ARGS_SIZE) return JSValueMakeNull(context); int i; for (i = 0; i < len; ++ i) { JSValueRef cur = JSObjectGetPropertyAtIndex(context, arr, i, NULL); JSStringRef str = JSValueToStringCopy(context, cur, NULL); size_t l = JSStringGetUTF8CString(str, cmd_str_buf + cmd_str_buf_cur, CMD_LINE_SIZE - cmd_str_buf_cur); cmd_idx_buf[i] = cmd_str_buf + cmd_str_buf_cur; cmd_str_buf_cur += l; JSStringRelease(str); JSValueUnprotect(context, cur); } cmd_idx_buf[i] = 0; if (fork() == 0) { /* Redirect I/O streams */ freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); execvp(cmd_idx_buf[0], cmd_idx_buf); fprintf(stderr, "RETURNED"); exit(1); } return JSValueMakeNull(context); }
static JSValueRef get_hint_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *hint_name = NULL; JSValueRef result; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } hint_name = arg_to_string(context, arguments[0], exception); if (!hint_name) { return JSValueMakeNull(context); } result = string_or_null(context, lightdm_greeter_get_hint(GREETER, hint_name)); g_free(hint_name); return result; }
static JSValueRef get_sessions_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { JSObjectRef array; const GList *sessions, *link; guint i, n_sessions = 0; JSValueRef *args; sessions = lightdm_get_sessions(); n_sessions = g_list_length((GList *) sessions); args = g_malloc(sizeof(JSValueRef) * ( n_sessions + 1 )); for (i = 0, link = sessions; link; i++, link = link->next) { LightDMSession *session = link->data; g_object_ref(session); args[i] = JSObjectMake(context, lightdm_session_class, session); } array = JSObjectMakeArray(context, n_sessions, args, exception); g_free(args); if (array == NULL) { return JSValueMakeNull(context); } else { return array; } }
static JSValueRef get_users_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { JSObjectRef array; const GList *users, *link; guint i, n_users = 0; JSValueRef *args; users = lightdm_user_list_get_users(lightdm_user_list_get_instance()); n_users = g_list_length((GList *) users); args = g_malloc(sizeof(JSValueRef) * ( n_users + 1 )); for (i = 0, link = users; link; i++, link = link->next) { LightDMUser *user = link->data; g_object_ref(user); args[i] = JSObjectMake(context, lightdm_user_class, user); } array = JSObjectMakeArray(context, n_users, args, exception); g_free(args); if (array == NULL) { return JSValueMakeNull(context); } else { return array; } }
/* * Tests whether a JavaScript value is an array object * * This invokes Array.isArray(value) and returns its result */ EXPORTAPI bool HyperloopJSValueIsArray(JSContextRef ctx, JSValueRef value) { if (JSValueIsObject(ctx, value)) { JSObjectRef global = JSContextGetGlobalObject(ctx); JSValueRef exception = JSValueMakeNull(ctx); JSStringRef string = JSStringCreateWithUTF8CString("Array"); JSObjectRef array = JSValueToObject(ctx, JSObjectGetProperty(ctx, global, string, &exception), &exception); JSStringRelease(string); if (!JSValueIsNull(ctx, exception)) { return false; } string = JSStringCreateWithUTF8CString("isArray"); JSObjectRef isArray = JSValueToObject(ctx, JSObjectGetProperty(ctx, array, string, &exception), &exception); JSStringRelease(string); if (!JSValueIsNull(ctx, exception)) { return false; } JSValueRef result = JSObjectCallAsFunction(ctx, isArray, global, 1, &value, &exception); if (JSValueIsNull(ctx, exception) && JSValueIsBoolean(ctx, result)) { return JSValueToBoolean(ctx, result); } } return false; }
JSValueRef function_set_exit_value(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef* exception) { if (argc == 1 && JSValueGetType (ctx, args[0]) == kJSTypeNumber) { exit_value = JSValueToNumber(ctx, args[0], NULL); } return JSValueMakeNull(ctx); }
VbResult hints_keypress(int key) { JSValueRef arguments[1]; if (key == KEY_CR) { hints_fire(); return RESULT_COMPLETE; } else if (key == CTRL('H')) { fire_timeout(false); arguments[0] = JSValueMakeNull(hints.ctx); if (call_hints_function("update", 1, arguments)) { return RESULT_COMPLETE; } } else if (key == KEY_TAB) { fire_timeout(false); hints_focus_next(false); return RESULT_COMPLETE; } else if (key == KEY_SHIFT_TAB) { fire_timeout(false); hints_focus_next(true); return RESULT_COMPLETE; } else { fire_timeout(true); /* try to handle the key by the javascript */ arguments[0] = js_string_to_ref(hints.ctx, (char[]){key, '\0'}); if (call_hints_function("update", 1, arguments)) { return RESULT_COMPLETE; } }
JS4D::ValueRef JS4D::VDurationToValue( ContextRef inContext, const VDuration& inDuration) { if (inDuration.IsNull()) return JSValueMakeNull( inContext); return JSValueMakeNumber( inContext, inDuration.ConvertToMilliseconds()); }
static JSValueRef gettext_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *string = NULL; JSValueRef result; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } string = arg_to_string(context, arguments[0], exception); if (!string) { return JSValueMakeNull(context); } result = string_or_null(context, gettext(string)); g_free(string); return result; }
JNIEXPORT jboolean JNICALL Java_com_appcelerator_hyperloop_ViewOnTouchListener_NativeOnTouch (JNIEnv *env, jobject thiz, jlong jsContextRef, jlong thisObjectRef, jlong onTouchFuncRef, jobject view, jobject event) { JSContextRef ctx = (JSContextRef)jsContextRef; JSObjectRef onTouchFunc = (JSObjectRef)onTouchFuncRef; JSObjectRef thisObject = (JSObjectRef)thisObjectRef; JSValueRef argv[2]; argv[0] = MakeObjectForJava_android_view_View(ctx, view); argv[1] = MakeObjectForJava_android_view_MotionEvent(ctx, event); if (JSObjectIsFunction(ctx, onTouchFunc)) { JSValueRef exception = JSValueMakeNull(ctx); JSValueRef result = JSObjectCallAsFunction(ctx, onTouchFunc, thisObject, 2, argv, &exception); if (!JSValueIsNull(ctx, exception)) { JSStringRef string = JSValueToStringCopy(ctx, exception, NULL); CCHAR_FROM_JSSTRINGREF(string, cstring); LOGD("Java_com_appcelerator_hyperloop_ViewOnTouchListener_NativeOnTouch '%s'", cstring); free(cstring); JSStringRelease(string); } return JSValueToBoolean(ctx, result) ? JNI_TRUE : JNI_FALSE; } return JNI_FALSE; }
JNIEXPORT void JNICALL Java_com_appcelerator_hyperloop_HyperloopJNI_HyperloopCallActivityOnCreate (JNIEnv *env, jobject thiz, jlong jsContextRef, jobject activity, jobject savedInstanceState) { JSContextRef context = (JSContextRef)jsContextRef; JSObjectRef globalObject = JSContextGetGlobalObject(context); JSStringRef onCreate = JSStringCreateWithUTF8CString("onCreate"); JSObjectRef onCreateFunc = JSValueToObject(context, JSObjectGetProperty(context, globalObject, onCreate, NULL), NULL); JSStringRelease(onCreate); // save current Activity JSObjectRef activityObj = MakeObjectForJava_android_app_Activity(context, activity); // save parameter JSValueRef args[1]; args[0] = MakeObjectForJava_android_os_Bundle(context, savedInstanceState); JSValueRef exception = JSValueMakeNull(context); // Call onCreate function if (JSObjectIsFunction(context, onCreateFunc)) { JSObjectCallAsFunction(context, onCreateFunc, activityObj, 1, args, &exception); } if (!JSValueIsNull(context, exception)) { JSStringRef string = JSValueToStringCopy(context, exception, NULL); CCHAR_FROM_JSSTRINGREF(string, cstring); LOGD("Java_com_appcelerator_hyperloop_HyperloopJNI_HyperloopCallActivityOnCreate '%s'", cstring); free(cstring); JSStringRelease(string); } }
static JSValueRef JSFeature_getProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { osgEarth::Features::Feature *feature = static_cast<osgEarth::Features::Feature*>(JSObjectGetPrivate(object)); char* attrBuf = JSUtils::JSStringRef_to_CharArray(propertyName); if (attrBuf) { std::string attr(attrBuf); delete [] attrBuf; if (attr == "attributes" || attr == "attrs") { return object; } osgEarth::Features::AttributeTable::const_iterator it = feature->getAttrs().find(attr); if (it != feature->getAttrs().end()) { osgEarth::Features::AttributeType atype = (*it).second.first; switch (atype) { case osgEarth::Features::ATTRTYPE_BOOL: return JSValueMakeBoolean(ctx, (*it).second.getBool()); case osgEarth::Features::ATTRTYPE_DOUBLE: return JSValueMakeNumber(ctx, (*it).second.getDouble()); case osgEarth::Features::ATTRTYPE_INT: return JSValueMakeNumber(ctx, (*it).second.getInt()); default: return JSValueMakeString(ctx, JSStringCreateWithUTF8CString((*it).second.getString().c_str())); } } } return JSValueMakeNull(ctx); }
JSObjectRef JSCArrayBuffer::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { uscxml::ArrayBuffer* localInstance = NULL; if (false) { } else if (argumentCount == 1 && JSValueIsNumber(ctx, arguments[0])) { unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); localInstance = new uscxml::ArrayBuffer(localLength); } if (!localInstance) { JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for ArrayBuffer"); *exception = JSValueMakeString(ctx, exceptionString); JSStringRelease(exceptionString); return (JSObjectRef)JSValueMakeNull(ctx); } JSClassRef retClass = JSCArrayBuffer::getTmpl(); struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); retPrivData->nativeObj = localInstance; JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); return retObj; }
static JSValueRef seed_gobject_signal_emit (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) { JSValueRef ret; GValue *params; GValue ret_value = { 0 }; GSignalQuery query; signal_privates *privates; guint i, signal_id; privates = JSObjectGetPrivate (thisObject); signal_id = g_signal_lookup (privates->signal_name, G_OBJECT_TYPE (privates->object)); g_signal_query (signal_id, &query); if (argumentCount != query.n_params) { seed_make_exception (ctx, exception, "ArgumentError", "Signal: %s for type %s expected %u " "arguments, got %zd", query.signal_name, g_type_name (query.itype), query.n_params, argumentCount); return JSValueMakeNull (ctx); } params = g_new0 (GValue, argumentCount + 1); g_value_init (¶ms[0], G_TYPE_OBJECT); g_value_set_object (¶ms[0], privates->object); for (i = 0; i < argumentCount; i++) seed_value_to_gvalue (ctx, arguments[i], query.param_types[i], ¶ms[i + 1], exception); if (query.return_type != G_TYPE_NONE) g_value_init (&ret_value, query.return_type); g_signal_emitv (params, signal_id, 0, &ret_value); for (i = 0; i < argumentCount; i++) g_value_unset (¶ms[i]); g_free (params); ret = seed_value_from_gvalue (ctx, &ret_value, exception); if (query.return_type != G_TYPE_NONE) g_value_unset (&ret_value); return ret; }
JSValueRef function_file_output_stream_write(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { if (argc == 2 && JSValueGetType(ctx, args[0]) == kJSTypeString && JSValueGetType(ctx, args[1]) == kJSTypeObject) { char *descriptor = value_to_c_string(ctx, args[0]); unsigned int count = (unsigned int) array_get_count(ctx, (JSObjectRef) args[1]); uint8_t buf[count]; for (unsigned int i = 0; i < count; i++) { JSValueRef v = array_get_value_at_index(ctx, (JSObjectRef) args[1], i); if (JSValueIsNumber(ctx, v)) { double n = JSValueToNumber(ctx, v, NULL); if (0 <= n && n <= 255) { buf[i] = (uint8_t) n; } else { fprintf(stderr, "Output stream value out of range %f", n); } } else { fprintf(stderr, "Output stream value not a number"); } } file_write(descriptor_str_to_int(descriptor), count, buf); free(descriptor); } return JSValueMakeNull(ctx); }
JSValueRef function_file_input_stream_read(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) { char *descriptor = value_to_c_string(ctx, args[0]); size_t buf_size = 4096; uint8_t *buf = malloc(buf_size * sizeof(uint8_t)); size_t read = file_read(descriptor_str_to_int(descriptor), buf_size, buf); free(descriptor); JSValueRef arguments[read]; int num_arguments = (int) read; for (int i = 0; i < num_arguments; i++) { arguments[i] = JSValueMakeNumber(ctx, buf[i]); } return JSObjectMakeArray(ctx, num_arguments, arguments, NULL); } return JSValueMakeNull(ctx); }
JSValueRef function_read_file(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { // TODO: implement fully if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) { char path[100]; JSStringRef path_str = JSValueToStringCopy(ctx, args[0], NULL); assert(JSStringGetLength(path_str) < 100); JSStringGetUTF8CString(path_str, path, 100); JSStringRelease(path_str); // debug_print_value("read_file", ctx, args[0]); time_t last_modified = 0; char *contents = get_contents(path, &last_modified); if (contents != NULL) { JSStringRef contents_str = JSStringCreateWithUTF8CString(contents); free(contents); JSValueRef res[2]; res[0] = JSValueMakeString(ctx, contents_str); res[1] = JSValueMakeNumber(ctx, last_modified); return JSObjectMakeArray(ctx, 2, res, NULL); } } return JSValueMakeNull(ctx); }
JSValueRef NativeFunctionCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { JSCallback* callback = static_cast<JSCallback*>(JSObjectGetPrivate(function)); if (!callback) return JSValueMakeNull(ctx); JSContextRef old_ctx = GetJSContext(); SetJSContext(ctx); JSArgs args; for (size_t i = 0; i < argumentCount; ++i) args.push_back(arguments[i]); (*callback)(thisObject, args); SetJSContext(old_ctx); return JSValueMakeNull(ctx); }
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(JSValueMakeNull) (JNIEnv *env, jclass that, jintLong arg0) { jintLong rc = 0; WebKit_win32_NATIVE_ENTER(env, that, JSValueMakeNull_FUNC); rc = (jintLong)JSValueMakeNull((JSContextRef)arg0); WebKit_win32_NATIVE_EXIT(env, that, JSValueMakeNull_FUNC); return rc; }
NATIVE(JSValue,jlong,makeNull) (PARAMS, jlong ctx) { JSContextWrapper *wrapper = (JSContextWrapper *)ctx; long lval = (long) wrapper->context; wrapper->worker_q->sync([](void *lval) { *((long *)lval) = (long) JSValueMakeNull((JSContextRef) *((long*)lval)); },&lval); return lval; }
JS4D::ValueRef JS4D::VStringToValue( ContextRef inContext, const VString& inString) { if (inString.IsNull()) return JSValueMakeNull( inContext); JSStringRef jsString = JSStringCreateWithCharacters( inString.GetCPointer(), inString.GetLength()); ValueRef value = JSValueMakeString( inContext, jsString); JSStringRelease( jsString); return value; }
JSValueRef function_raw_write_stderr(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) { char *s = value_to_c_string(ctx, args[0]); fprintf(stderr, "%s", s); free(s); } return JSValueMakeNull(ctx); }
bool web_view_callback (struct js_callback_data *data) { unsigned short i; JSValueRef js_args[data->args_len]; for (i = 0; i < data->args_len; i++) { switch (data->args[i].type) { case kJSTypeBoolean: js_args[i] = JSValueMakeBoolean(data->widget->js_context, data->args[i].value.boolean); break; case kJSTypeNull: js_args[i] = JSValueMakeNull(data->widget->js_context); break; case kJSTypeNumber: js_args[i] = JSValueMakeNumber(data->widget->js_context, data->args[i].value.number); break; case kJSTypeObject: js_args[i] = data->args[i].value.object; break; case kJSTypeString: { JSStringRef str = JSStringCreateWithUTF8CString(data->args[i].value.string); js_args[i] = JSValueMakeString(data->widget->js_context, str); JSStringRelease(str); break; } case kJSTypeUndefined: js_args[i] = JSValueMakeUndefined(data->widget->js_context); break; } } if (!data->widget->js_context || !data->widget->js_object) { LOG_ERR("missing JS context or object!"); return false; } JSStringRef str_ondatachanged = JSStringCreateWithUTF8CString("onDataChanged"); JSValueRef func = JSObjectGetProperty(data->widget->js_context, data->widget->js_object, str_ondatachanged, NULL); JSObjectRef function = JSValueToObject(data->widget->js_context, func, NULL); JSStringRelease(str_ondatachanged); /* let the thread know we're done with the data so it can cleanup */ pthread_cond_signal(&update_cond); if (!JSObjectIsFunction(data->widget->js_context, function)) { LOG_DEBUG("onDataChanged callback for 'widget_%s' with type '%s' is not a function or is not set", data->widget->name, data->widget->type); return false; /* only run once */ } JSObjectCallAsFunction(data->widget->js_context, function, NULL, data->args_len, js_args, NULL); return false; /* only run once */ }