Beispiel #1
0
static JSValueRef nativeobject_ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception)
{
	if ( type == kJSTypeString ) {
		void* data = JSObjectGetPrivate( object );
		JSStringRef str = nativeobject_ConvertToString_go( data, (void*)ctx, (void*)object );
		if ( !str ) {
			str = JSStringCreateWithUTF8CString( "nativeobject" );
		}
		JSValueRef ret = JSValueMakeString( ctx, str );
		JSStringRelease( str );
		return ret;
	}

	return 0;
}
Beispiel #2
0
JSValueRef JSCDocumentType::notationsAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
	struct JSCDocumentTypePrivate* privData = (struct JSCDocumentTypePrivate*)JSObjectGetPrivate(object);


	Arabica::DOM::NamedNodeMap<std::string>* arabicaRet = new Arabica::DOM::NamedNodeMap<std::string>(privData->nativeObj->getNotations());

	JSClassRef arbaicaRetClass = JSCNamedNodeMap::getTmpl();

	struct JSCNamedNodeMap::JSCNamedNodeMapPrivate* retPrivData = new JSCNamedNodeMap::JSCNamedNodeMapPrivate();
	retPrivData->dom = privData->dom;
	retPrivData->nativeObj = arabicaRet;

	JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData);
	return arbaicaRetObj;
}
Beispiel #3
0
static JSValueRef console_getSharedValue(JSContextRef ctx, JSObjectRef thisObject, JSStringRef /*propertyName*/, JSValueRef* /*exception*/)
{
    if (!JSValueIsObjectOfClass(ctx, thisObject, ConsoleClass()))
        return JSValueMakeUndefined(ctx);

    CallJSDlg* dlg = static_cast<CallJSDlg*>(JSObjectGetPrivate(thisObject));
    if (!dlg)
        return JSValueMakeUndefined(ctx);

    JSStringRef jsString = JSStringCreateWithBSTR(dlg->sharedString());
    JSValueRef jsValue = JSValueMakeString(ctx, jsString);
    JSStringRelease(jsString);

    return jsValue;
}
Beispiel #4
0
static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
    UNUSED_PARAM(propertyName);
    UNUSED_PARAM(exception);

    Node* node = JSObjectGetPrivate(object);
    if (node) {
        JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
        JSValueRef value = JSValueMakeString(context, nodeType);
        JSStringRelease(nodeType);
        return value;
    }
    
    return NULL;
}
 static JSValueRef call(
     JSContextRef ctx,
     JSObjectRef function,
     JSObjectRef thisObject,
     size_t argumentCount,
     const JSValueRef arguments[],
     JSValueRef *exception) {
   try {
     auto globalObj = JSContextGetGlobalObject(ctx);
     auto executor = static_cast<JSCExecutor*>(JSObjectGetPrivate(globalObj));
     return (executor->*method)(argumentCount, arguments);
   } catch (...) {
     *exception = translatePendingCppExceptionToJSError(ctx, function);
     return JSValueMakeUndefined(ctx);
   }
 }
static JSValueRef highlightDOMNode(JSContextRef context, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/)
{
    JSValueRef undefined = JSValueMakeUndefined(context);

    InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
    if (argumentCount < 1 || !controller)
        return undefined;

    Node* node = toNode(toJS(arguments[0]));
    if (!node)
        return undefined;

    controller->highlight(node);

    return undefined;
}
Beispiel #7
0
JSValueRef JSCDocument::localStorageCustomAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
	struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(object);

	if (!privData->dom->storage) {
		return JSValueMakeUndefined(ctx);
	}

	JSClassRef retClass = JSCStorage::getTmpl();
	struct JSCStorage::JSCStoragePrivate* retPrivData = new JSCStorage::JSCStoragePrivate();
	retPrivData->dom = privData->dom;
	retPrivData->nativeObj = retPrivData->dom->storage;

	JSObjectRef arbaicaRetObj = JSObjectMake(ctx, retClass, retPrivData);
	return arbaicaRetObj;

}
static JSValueRef qt_postWebChannelMessageCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef*)
{
    // FIXME: should it work regardless of the thisObject?

    if (argumentCount < 1 || !JSValueIsString(context, arguments[0]))
        return JSValueMakeUndefined(context);

    QtBuiltinBundlePage* bundlePage = reinterpret_cast<QtBuiltinBundlePage*>(JSObjectGetPrivate(thisObject));
    ASSERT(bundlePage);

    // TODO: can we transmit the data as JS object, instead of as a string?
    JSRetainPtr<JSStringRef> jsContents = JSValueToStringCopy(context, arguments[0], 0);
    WKRetainPtr<WKStringRef> contents(AdoptWK, WKStringCreateWithJSString(jsContents.get()));
    bundlePage->postMessageFromNavigatorQtWebChannelTransport(contents.get());
    return JSValueMakeUndefined(context);
}
Beispiel #9
0
JSValueRef js_event_start_timer_func(JSContextRef cx,JSObjectRef func,JSObjectRef j_obj,size_t argc,const JSValueRef argv[],JSValueRef *exception)
{
	int				script_idx;
	char			err_str[256];

	if (!script_check_param_count(cx,func,argc,2,exception)) return(script_null_to_value(cx));
	if (!script_check_fail_in_construct(cx,func,j_obj,exception)) return(script_null_to_value(cx));

	script_idx=(int)JSObjectGetPrivate(j_obj);

	if (!timers_add(script_idx,script_value_to_int(cx,argv[0]),script_value_to_int(cx,argv[1]),NULL,timer_mode_repeat,err_str)) {
		*exception=script_create_exception(cx,err_str);
		return(script_bool_to_value(cx,FALSE));
	}

	return(script_bool_to_value(cx,TRUE));
}
Beispiel #10
0
static bool console_setSharedDouble(JSContextRef ctx, JSObjectRef thisObject, JSStringRef /*propertyName*/, JSValueRef value, JSValueRef* exception)
{
    if (!JSValueIsNumber(ctx, value))
        return false;

    CallJSDlg* dlg = static_cast<CallJSDlg*>(JSObjectGetPrivate(thisObject));
    if (!dlg)
        return false;

    double temp = JSValueToNumber (ctx, value, exception);
    if (exception && *exception)
        return false;

    dlg->setSharedDouble(temp);

    return true;
}
Beispiel #11
0
JSValueRef NativeFunctionWithRetvalCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
  size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
  JSCallbackWithRetval* callback = static_cast<JSCallbackWithRetval*>(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]);

  JSValueRef result = (*callback)(thisObject, args);
  SetJSContext(old_ctx);

  return result;
}
static JSValueRef getProperty(JSContextRef jscore_ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
{
	pdf_jsimp *imp;
	char buf[STRING_BUF_SIZE];
	prop *p;
	JSValueRef res = NULL;

	priv_data *pdata = JSObjectGetPrivate(object);
	if (pdata == NULL)
		return NULL;

	JSStringGetUTF8CString(propertyName, buf, STRING_BUF_SIZE);
	p = find_prop(pdata->type->props, buf);
	if (p == NULL)
		return NULL;

	imp = pdata->type->imp;

	switch(p->type)
	{
		case PROP_FN:
			{
				/*
					For some reason passing the method pointer as private data doesn't work: the data comes back
					NULL when interrogated in callMethod above. So we also specify the method name when
					creating the function so that we can look it up again in callMethod. Not ideal, but
					will do until we can find a better solution.
				*/
				JSObjectRef ores = JSObjectMakeFunctionWithCallback(jscore_ctx, propertyName, callMethod);
				JSObjectSetPrivate(ores, p->u.fn.meth);
				res = ores;
			}
			break;

		case PROP_VAL:
			{
				pdf_jsimp_obj *pres = p->u.val.get(imp->nat_ctx, pdata->natobj);
				res = pres->ref;
				pdf_jsimp_drop_obj(imp, pres);
			}
			break;
	}

	return res;
}
Beispiel #13
0
static bool
gumjs_proxy_has_property (JSContextRef ctx,
                          JSObjectRef object,
                          JSStringRef property_name)
{
  GumJscProxy * self;
  GumJscCore * core;

  self = GUMJS_PROXY (object);
  if (self->has == NULL)
    return false;

  core = JSObjectGetPrivate (JSContextGetGlobalObject (ctx));

  {
    GumJscScope scope = GUM_JSC_SCOPE_INIT (core);
    JSValueRef * ex = &scope.exception;
    JSValueRef property_name_value, value;
    bool result = false;

    property_name_value = JSValueMakeString (ctx, property_name);
    value = JSObjectCallAsFunction (ctx, self->has, self->receiver,
        1, &property_name_value, ex);
    if (value == NULL)
      goto beach;

    if (!JSValueIsBoolean (ctx, value))
      goto invalid_result_type;

    result = JSValueToBoolean (ctx, value);

    goto beach;

invalid_result_type:
    {
      _gumjs_throw (ctx, ex, "expected has() to return a boolean");
      goto beach;
    }
beach:
    {
      _gum_jsc_scope_flush (&scope);
      return result;
    }
  }
}
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
    KJS::JSLock lock(false);

    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
        return JSValueMakeUndefined(ctx);

    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
    const Vector<RefPtr<ProfileNode> >& children = profileNode->children();

    JSObjectRef global = JSContextGetGlobalObject(ctx);

    JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array"));

    JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push"));
    
    JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) {
        JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() ));
        JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
        if (exception && *exception)
            return JSValueMakeUndefined(ctx);
    }

    return result;
}
JSValueRef getActionForJava_android_view_MotionEvent(JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    JSPrivateObject* p = (JSPrivateObject*)JSObjectGetPrivate(object);
    if (p && p->object) {
        JNI_ENV_ENTER
        jclass  javaClass = (*env)->FindClass(env, "android/view/MotionEvent");
        if (javaClass == NULL) return HyperloopMakeException(ctx, "Class not found: android.view.MotionEvent", exception);
        
        jmethodID methodId = (*env)->GetMethodID(env, javaClass, "getAction", "()I");
        if (methodId == NULL) return HyperloopMakeException(ctx, "Method not found: android.view.MotionEvent#getAction", exception);
        (*env)->DeleteLocalRef(env, javaClass);
        
        jint result = (*env)->CallIntMethod(env, p->object, methodId);
        CHECK_JAVAEXCEPTION
        JNI_ENV_EXIT
        
        return JSValueMakeNumber(ctx, (int)result);
    }
Beispiel #16
0
/**
 * The callback from JavaScriptCore.  We told JSC to call this function
 * whenever it sees "console.report".
 */
static JSValueRef console_report(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception)
{
    if (!JSValueIsObjectOfClass(ctx, thisObject, ConsoleClass()))
        return JSValueMakeUndefined(ctx);

    CallJSDlg* dlg = static_cast<CallJSDlg*>(JSObjectGetPrivate(thisObject));
    if (!dlg)
        return JSValueMakeUndefined(ctx);

    if (argumentCount)
        return JSValueMakeUndefined(ctx);

    JSStringRef jsString = JSStringCreateWithBSTR(dlg->sharedString());
    JSValueRef jsValue = JSValueMakeString(ctx, jsString);
    JSStringRelease(jsString);

    return jsValue;
}
static JSValueRef
JSOSInstaller_setRestart(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (!JSValueIsObjectOfClass(context, thisObject, JSOSInstaller_class(context))) {
        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: setRestart can only be called on JSOSInstaller");
        *exception = JSValueMakeString(context, message);
        JSStringRelease(message);
    } else if (argumentCount < 1 || !JSValueIsBoolean(context, arguments[0])) {
        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to setRestart must be a boolean");
        *exception = JSValueMakeString(context, message);
        JSStringRelease(message);
    } else {
        JSInstaller* jsinst = JSObjectGetPrivate(thisObject);
        jsinst->restart = JSValueToBoolean(context,arguments[0]);
    }

    return JSValueMakeUndefined(context);
}
static JSValueRef
JSOSInstaller_setDoneHookFunc(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (!JSValueIsObjectOfClass(context, thisObject, JSOSInstaller_class(context))) {
        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: SetDoneHookFunc can only be called on JSOSInstaller");
        *exception = JSValueMakeString(context, message);
        JSStringRelease(message);
    } else if (argumentCount < 1 || !JSValueIsObject(context, arguments[0])) {
        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to SetDoneHookFunc must be a callable");
        *exception = JSValueMakeString(context, message);
        JSStringRelease(message);
    } else {
        JSInstaller* jsinst = JSObjectGetPrivate(thisObject);
        jsinst->done_func = JSValueToObject(context,arguments[0],exception);
    }

    return JSValueMakeUndefined(context);
}
Beispiel #19
0
JSValueRef JSCArrayBuffer::sliceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {

	struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj);

	if (false) {
	} else if (argumentCount == 2 &&
	           JSValueIsNumber(ctx, arguments[0]) &&
	           JSValueIsNumber(ctx, arguments[1])) {
		long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception);
		long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception);

		uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd));
		JSClassRef retClass = JSCArrayBuffer::getTmpl();

		struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate();
		retPrivData->dom = privData->dom;
		retPrivData->nativeObj = retVal;

		JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);

		return retObj;

	} else if (argumentCount == 1 &&
	           JSValueIsNumber(ctx, arguments[0])) {
		long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception);

		uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin));
		JSClassRef retClass = JSCArrayBuffer::getTmpl();

		struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate();
		retPrivData->dom = privData->dom;
		retPrivData->nativeObj = retVal;

		JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);

		return retObj;

	}

	JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling slice");
	*exception = JSValueMakeString(ctx, exceptionString);
	JSStringRelease(exceptionString);
	return JSValueMakeUndefined(ctx);
}
static JSValueRef qt_postMessageCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef*)
{
    // FIXME: should it work regardless of the thisObject?

    if (argumentCount < 1 || !JSValueIsString(context, arguments[0]))
        return JSValueMakeUndefined(context);

    QtBuiltinBundlePage* bundlePage = reinterpret_cast<QtBuiltinBundlePage*>(JSObjectGetPrivate(thisObject));
    ASSERT(bundlePage);

    // FIXME: needed?
    if (!bundlePage->navigatorQtObjectEnabled())
        return JSValueMakeUndefined(context);

    JSRetainPtr<JSStringRef> jsContents = JSValueToStringCopy(context, arguments[0], 0);
    WKRetainPtr<WKStringRef> contents(AdoptWK, WKStringCreateWithJSString(jsContents.get()));
    bundlePage->postMessageFromNavigatorQtObject(contents.get());
    return JSValueMakeUndefined(context);
}
JSValueRef setMarginsForJava_android_widget_FrameLayout_LayoutParams(JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    JSPrivateObject* p = (JSPrivateObject*)JSObjectGetPrivate(object);
    if (p && p->object && argumentCount >= 4) {
        int arg0 = JSValueToNumber(ctx, arguments[0], exception);
        int arg1 = JSValueToNumber(ctx, arguments[1], exception);
        int arg2 = JSValueToNumber(ctx, arguments[2], exception);
        int arg3 = JSValueToNumber(ctx, arguments[3], exception);
        JNI_ENV_ENTER
        jclass  javaClass = (*env)->FindClass(env, "android/widget/FrameLayout$LayoutParams");
        if (javaClass == NULL) return HyperloopMakeException(ctx, "Class not found: android.widget.FrameLayout$LayoutParams", exception);
        
        jmethodID methodId = (*env)->GetMethodID(env, javaClass, "setMargins", "(IIII)V");
        if (methodId == NULL) return HyperloopMakeException(ctx, "Method not found: android.widget.FrameLayout$LayoutParams#setMargins", exception);
        
        (*env)->DeleteLocalRef(env, javaClass);
        (*env)->CallVoidMethod(env, p->object, methodId, arg0, arg1, arg2, arg3);
        JNI_ENV_EXIT
    }
Beispiel #22
0
BB::PatchCollection* BB::PatchCollection::FromJS(JSContextRef ctx,
												 JSObjectRef object)
{
	BB::Context * context;
	BB::PatchCollection * collection;
	
	if (ctx != NULL)
	{
		context = BB::Context::FromJS(ctx);
		if (!JSValueIsObjectOfClass(ctx, object, context->patchCollectionClass()))
		{
			return NULL;
		}
	}
	
	collection = static_cast<BB::PatchCollection*>(JSObjectGetPrivate(object));
	
	return collection;
}
static JSValueRef selectedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject));

    if (controller) {
        vector<int> rect = controller->selectedRange();
        if (rect.size() == 2) {
            JSValueRef argumentsArrayValues[] = { 
                JSValueMakeNumber(context, rect[0]), 
                JSValueMakeNumber(context, rect[1]), 
            };
            JSObjectRef result = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, exception);
            ASSERT(!*exception);
            return result;
        }
    }

    return JSValueMakeUndefined(context);
}
Beispiel #24
0
JSValueRef JSCInt16Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {

	struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(thisObj);

	if (false) {
	} else if (argumentCount == 1 &&
	           JSValueIsNumber(ctx, arguments[0])) {
		unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception);

		short retVal = privData->nativeObj->get(localIndex);

		JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal);
		return jscRetVal;
	}

	JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get");
	*exception = JSValueMakeString(ctx, exceptionString);
	JSStringRelease(exceptionString);
	return JSValueMakeUndefined(ctx);
}
Beispiel #25
0
proj_setup_type* proj_setup_get_attach(JSObjectRef j_obj)
{
	int					script_idx;
	obj_type			*obj;
	weapon_type			*weap;
	script_type			*script;
	
	script_idx=(int)JSObjectGetPrivate(j_obj);
	script=js.script_list.scripts[script_idx];

	if (script->attach.obj_idx==-1) return(NULL);
	if (script->attach.weap_idx==-1) return(NULL);
	if (script->attach.proj_setup_idx==-1) return(NULL);

	obj=server.obj_list.objs[script->attach.obj_idx];
	if (obj==NULL) return(NULL);

	weap=obj->weap_list.weaps[script->attach.weap_idx];
	return(weap->proj_setup_list.proj_setups[script->attach.proj_setup_idx]);
}
Beispiel #26
0
static JSValueRef
seed_signal_holder_get_property (JSContextRef ctx,
				 JSObjectRef object,
				 JSStringRef property_name,
				 JSValueRef * exception)
{
  GObject *gobj = JSObjectGetPrivate (object);
  signal_privates *priv;
  guint length = JSStringGetMaximumUTF8CStringSize (property_name);
  gchar *signal_name = g_malloc (length * sizeof (gchar));
  JSObjectRef signal_ref;

  JSStringGetUTF8CString (property_name, signal_name, length);

  if (!
      (g_strcmp0 (signal_name, "connect")
       && g_strcmp0 (signal_name, "disconnect")))
    {
      g_free (signal_name);
      return NULL;
    }

  if (!g_str_has_prefix (signal_name, "notify::") &&
      !g_signal_lookup (signal_name, G_OBJECT_TYPE (gobj)))
    {
      seed_make_exception (ctx, exception, "InvalidSignalName",
			   "Failed to connect to %s. "
			   "Invalid signal name.", signal_name);
      g_free (signal_name);
      return NULL;
    }

  priv = g_slice_alloc (sizeof (signal_privates));

  priv->object = gobj;
  priv->signal_name = signal_name;

  signal_ref = JSObjectMake (ctx, gobject_signal_class, priv);

  return signal_ref;
}
static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (argumentCount < 3)
        return JSValueMakeUndefined(context);

    JSRetainPtr<JSStringRef> str(Adopt, JSValueToStringCopy(context, arguments[0], exception));
    ASSERT(!*exception);

    double from = JSValueToNumber(context, arguments[1], exception);
    ASSERT(!*exception);

    double length = JSValueToNumber(context, arguments[2], exception);
    ASSERT(!*exception);

    TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject));
    
    if (controller)
        controller->setMarkedText(str.get(), from, length);

    return JSValueMakeUndefined(context);
}
Beispiel #28
0
JSValueRef js_event_start_wait_random_func(JSContextRef cx,JSObjectRef func,JSObjectRef j_obj,size_t argc,const JSValueRef argv[],JSValueRef *exception)
{
	int				min,max,tick,script_idx;
	char			err_str[256];
	
	if (!script_check_param_count(cx,func,argc,3,exception)) return(script_null_to_value(cx));
	if (!script_check_fail_in_construct(cx,func,j_obj,exception)) return(script_null_to_value(cx));
	
	script_idx=(int)JSObjectGetPrivate(j_obj);
	
	min=script_value_to_int(cx,argv[0]);
	max=script_value_to_int(cx,argv[1]);
	tick=random_int(abs(max-min))+min;
	
	if (!timers_add(script_idx,tick,script_value_to_int(cx,argv[2]),NULL,timer_mode_single,err_str)) {
		*exception=script_create_exception(cx,err_str);
		return(script_bool_to_value(cx,FALSE));
	}

	return(script_bool_to_value(cx,TRUE));
}
Beispiel #29
0
JSObjectRef ej_callAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argc, const JSValueRef argv[], JSValueRef* exception) {



    EJBindingBase* pClass = (EJBindingBase*)(JSObjectGetPrivate( constructor ));

    NSLOG("ej_callAsConstructor constructor: %s()", pClass->toString().c_str());

    JSClassRef jsClass = EJApp::instance()->getJSClassForClass(pClass);

    JSObjectRef obj = JSObjectMake( ctx, jsClass, NULL );

    EJBindingBase* instance = (EJBindingBase*)NSClassFromString(pClass->toString().c_str());
    instance->init(ctx, obj, argc, argv);

    NSLOG("binding constructor: %s", instance->toString().c_str());

    JSObjectSetPrivate( obj, (void *)instance );

    return obj;
}
Beispiel #30
0
static JSValueRef
seed_gobject_signal_disconnect (JSContextRef ctx,
				JSObjectRef function,
				JSObjectRef thisObject,
				size_t argumentCount,
				const JSValueRef arguments[],
				JSValueRef * exception)
{
  gulong id;
  if (argumentCount != 1)
    {
      seed_make_exception (ctx, exception, "ArgumentError",
			   "Signal disconnection expects 1 argument"
			   " got %zd", argumentCount);
      return JSValueMakeUndefined (ctx);
    }
  id = seed_value_to_ulong (ctx, arguments[0], exception);
  g_signal_handler_disconnect (JSObjectGetPrivate (thisObject), id);

  return JSValueMakeUndefined (ctx);
}