Ejemplo n.º 1
0
Archivo: ns_net.c Proyecto: vifino/dwb
static JSValueRef
get_message_data(SoupMessage *msg)
{
    const char *name, *value;
    SoupMessageHeadersIter iter;
    JSObjectRef o = NULL, ho;
    JSValueRef ret;
    JSStringRef s;

    JSContextRef ctx = scripts_get_global_context();
    if (ctx == NULL) {
        return NIL;
    }

    o = JSObjectMake(ctx, NULL, NULL);
    js_set_object_property(ctx, o, "body", msg->response_body->data, NULL);

    ho = JSObjectMake(ctx, NULL, NULL);

    soup_message_headers_iter_init(&iter, msg->response_headers);
    while (soup_message_headers_iter_next(&iter, &name, &value))
        js_set_object_property(ctx, ho, name, value, NULL);

    s = JSStringCreateWithUTF8CString("headers");
    JSObjectSetProperty(ctx, o, s, ho, kJSDefaultProperty, NULL);
    JSStringRelease(s);
    ret = o;

    scripts_release_global_context();

    return ret;
}
Ejemplo n.º 2
0
/**
 * internal 
 *
 * setup a context after created
 */
static void InitializeContext (JSGlobalContextRef ctx)
{
    auto global = JSContextGetGlobalObject(ctx);
    auto setterProps = kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete;

    // inject a simple console logger
    auto logProperty = JSStringCreateWithUTF8CString("log");
    auto consoleProperty = JSStringCreateWithUTF8CString("console");
    auto consoleObject = JSObjectMake(ctx, 0, 0);
    auto logFunction = JSObjectMakeFunctionWithCallback(ctx, logProperty, HyperloopLogger);
    JSObjectSetProperty(ctx, consoleObject, logProperty, logFunction, setterProps, 0);
    JSObjectSetProperty(ctx, global, consoleProperty, consoleObject, setterProps, 0);
    JSStringRelease(logProperty);
    JSStringRelease(consoleProperty);

    // bind some internal cross-platform methods
    auto vmBindingProperty = JSStringCreateWithUTF8CString("hyperloop$vm");
    auto vmrunInNewContextProperty = JSStringCreateWithUTF8CString("runInNewContext");
    auto vmBindingObject = JSObjectMake(ctx, 0, 0);
    auto vmrunInNewContextFunction = JSObjectMakeFunctionWithCallback(ctx, vmrunInNewContextProperty, RunInNewContext);
    JSObjectSetProperty(ctx, vmBindingObject, vmrunInNewContextProperty, vmrunInNewContextFunction, setterProps, 0);
    JSObjectSetProperty(ctx, global, vmBindingProperty, vmBindingObject, setterProps, 0);
    JSStringRelease(vmBindingProperty);
    JSStringRelease(vmrunInNewContextProperty);

    // create a hook into our global context
    auto prop = JSStringCreateWithUTF8CString("hyperloop$global");
    JSObjectSetProperty(ctx, global, prop, global, setterProps, 0);
    JSStringRelease(prop);

    // setup our globals object -- should point to the real root global object if a new context (not the root ctx)
    auto globalProperty = JSStringCreateWithUTF8CString("global");
    JSObjectSetProperty(ctx, global, globalProperty, global, setterProps, 0);
    JSStringRelease(globalProperty);
}
Ejemplo n.º 3
0
/*
 * Set up prototype and constructor for structs. Same semantics as objects
 * except
 * for the type.
 */
static void
seed_gi_importer_handle_struct(JSContextRef ctx,
                               JSObjectRef namespace_ref,
                               GIStructInfo* info,
                               JSValueRef* exception)
{
    JSObjectRef struct_ref;
    JSObjectRef proto;
    gint i, n_methods;
    GIFunctionInfo* finfo;

    struct_ref = JSObjectMake(ctx, seed_struct_constructor_class, info);
    g_base_info_ref(info);

    n_methods = g_struct_info_get_n_methods(info);

    for (i = 0; i < n_methods; i++) {
        GIFunctionInfoFlags flags;
        finfo = g_struct_info_get_method(info, i);

        flags = g_function_info_get_flags(finfo);

        if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
            JSObjectRef constructor
              = JSObjectMake(ctx, gobject_named_constructor_class, finfo);
            const gchar* fname = g_base_info_get_name((GIBaseInfo*) finfo);
            if (g_strrstr(fname, "new_") == fname) {
                // To be compatible with gjs, we need to have a method with
                // new_, too.
                seed_object_set_property(ctx, struct_ref, fname, constructor);
                fname += 4;
            }

            else if (!g_strcmp0(fname, "new")) {
                // To be compatible with gjs, we need to have new as function,
                // too.
                seed_object_set_property(ctx, struct_ref, fname, constructor);
                fname = "c_new";
            }

            seed_object_set_property(ctx, struct_ref, fname, constructor);
        } else if (flags & GI_FUNCTION_IS_METHOD)
            g_base_info_unref((GIBaseInfo*) finfo);
        else
            seed_gobject_define_property_from_function_info(ctx, finfo,
                                                            struct_ref, FALSE);
    }

    proto = seed_struct_prototype(ctx, (GIBaseInfo*) info);
    seed_object_set_property(ctx, struct_ref, "prototype", proto);

    seed_object_set_property(ctx, namespace_ref,
                             g_base_info_get_name((GIBaseInfo*) info),
                             struct_ref);
}
Ejemplo n.º 4
0
static gboolean
gum_emit_range (const GumRangeDetails * details,
                gpointer user_data)
{
  GumJscMatchContext * mc = user_data;
  GumJscCore * core = mc->self->core;
  GumJscScope scope = GUM_JSC_SCOPE_INIT (core);
  JSContextRef ctx = mc->ctx;
  char prot_str[4] = "---";
  JSObjectRef range;
  const GumFileMapping * f = details->file;
  JSValueRef result;
  gboolean proceed;
  gchar * str;

  if ((details->prot & GUM_PAGE_READ) != 0)
    prot_str[0] = 'r';
  if ((details->prot & GUM_PAGE_WRITE) != 0)
    prot_str[1] = 'w';
  if ((details->prot & GUM_PAGE_EXECUTE) != 0)
    prot_str[2] = 'x';

  range = JSObjectMake (ctx, NULL, NULL);
  _gumjs_object_set_pointer (ctx, range, "base",
      GSIZE_TO_POINTER (details->range->base_address), core);
  _gumjs_object_set_uint (ctx, range, "size", details->range->size);
  _gumjs_object_set_string (ctx, range, "protection", prot_str);

  if (f != NULL)
  {
    JSObjectRef file = JSObjectMake (ctx, NULL, NULL);
    _gumjs_object_set_string (ctx, file, "path", f->path);
    _gumjs_object_set_uint (ctx, file, "offset", f->offset);
    _gumjs_object_set (ctx, range, "file", file);
  }

  result = JSObjectCallAsFunction (ctx, mc->on_match, NULL, 1,
      (JSValueRef *) &range, &scope.exception);
  _gum_jsc_scope_flush (&scope);

  proceed = TRUE;
  if (result != NULL && _gumjs_string_try_get (ctx, result, &str, NULL))
  {
    proceed = strcmp (str, "stop") != 0;
    g_free (str);
  }

  return proceed;
}
Ejemplo n.º 5
0
BB::PatchCollection::PatchCollection(BB::Context& context)
 :	m_context(context)
{
	JSContextRef ctx;
	ctx = context.context();
	this->m_patch_collection_object = JSObjectMake(ctx, context.patchCollectionClass(), this);
}
Ejemplo n.º 6
0
static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec)
{
    JSObject* constructor = exec->callee();
    JSContextRef ctx = toRef(exec);
    JSObjectRef constructorRef = toRef(constructor);

    JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
    if (callback) {
        int argumentCount = static_cast<int>(exec->argumentCount());
        Vector<JSValueRef, 16> arguments(argumentCount);
        for (int i = 0; i < argumentCount; i++)
            arguments[i] = toRef(exec, exec->argument(i));

        JSValueRef exception = 0;
        JSObjectRef result;
        {
            APICallbackShim callbackShim(exec);
            result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
        }
        if (exception)
            throwError(exec, toJS(exec, exception));
        return JSValue::encode(toJS(result));
    }
    
    return JSValue::encode(toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0)));
}
Ejemplo n.º 7
0
pdf_jsimp_obj *pdf_jsimp_new_obj(pdf_jsimp *imp, pdf_jsimp_type *type, void *natobj)
{
	fz_context *ctx = imp->ctx;
	pdf_jsimp_obj *obj = fz_malloc_struct(ctx, pdf_jsimp_obj);
	priv_data *pdata = NULL;

	fz_var(pdata);
	fz_try(ctx)
	{
		pdata = fz_malloc_struct(ctx, priv_data);
		pdata->type = type;
		pdata->natobj = natobj;
		obj->ref = JSObjectMake(imp->jscore_ctx, imp->class_ref, pdata);
		if (obj->ref == NULL)
			fz_throw(ctx, FZ_ERROR_GENERIC, "JSObjectMake failed");

		JSValueProtect(imp->jscore_ctx, obj->ref);
	}
	fz_catch(ctx)
	{
		fz_free(ctx, pdata);
		fz_free(ctx, obj);
		fz_rethrow(ctx);
	}

	return obj;
}
Ejemplo n.º 8
0
 EJ_BIND_FUNCTION(EJBindingCanvas,createImageData, ctx, argc, argv) {
 	if( argc < 2 ) { return NULL; }
	
 	float
 		sw = JSValueToNumberFast(ctx, argv[0]),
 		sh = JSValueToNumberFast(ctx, argv[1]);
		
 	GLubyte * pixels = (GLubyte *)calloc( sw * sh * 4, sizeof(GLubyte) );
 	EJImageData * imageData = new EJImageData(sw ,sh ,pixels);
 	imageData->autorelease();

 	// Create the JS object
 	EJBindingImageData* tempData = new EJBindingImageData();
 	JSClassRef imageDataClass = EJApp::instance()->getJSClassForClass((EJBindingBase*)tempData);
 	delete tempData;
 	JSObjectRef obj = JSObjectMake( ctx, imageDataClass, NULL );
 	JSValueProtect(ctx, obj);

 	// Create the native instance
 	EJBindingImageData * jsImageData =new EJBindingImageData(ctx,obj,imageData);

 	// Attach the native instance to the js object
 	JSObjectSetPrivate( obj, (void *)jsImageData );
 	JSValueUnprotect(ctx, obj);
 	return obj;
 }
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;
	}
}
Ejemplo n.º 11
0
void
_gum_jsc_polyfill_init (GumJscPolyfill * self,
                        GumJscCore * core,
                        JSObjectRef scope)
{
  JSContextRef ctx = core->ctx;
  JSClassDefinition def;
  JSClassRef klass;
  JSObjectRef module;

  self->core = core;

  def = kJSClassDefinitionEmpty;
  def.className = "ProxyModule";
  def.staticFunctions = gumjs_proxy_module_functions;
  klass = JSClassCreate (&def);
  module = JSObjectMake (ctx, klass, self);
  JSClassRelease (klass);
  _gumjs_object_set (ctx, scope, "Proxy", module);

  def = kJSClassDefinitionEmpty;
  def.attributes = kJSClassAttributeNoAutomaticPrototype;
  def.className = "Proxy";
  def.finalize = gumjs_proxy_finalize;
  def.hasProperty = gumjs_proxy_has_property;
  def.getProperty = gumjs_proxy_get_property;
  def.setProperty = gumjs_proxy_set_property;
  def.getPropertyNames = gumjs_proxy_get_property_names;
  self->proxy = JSClassCreate (&def);
}
Ejemplo n.º 12
0
JSObjectRef JSOSInstaller_new(JSContextRef context, JSInstaller* jsinst)
{
    JSObjectRef jsobj;
    jsobj = JSObjectMake(context, JSOSInstaller_class(context), jsinst);
    jsinst->js_self = jsobj;
    return jsobj;
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec)
{
    JSObject* constructor = exec->callee();
    JSContextRef ctx = toRef(exec);
    JSObjectRef constructorRef = toRef(constructor);

    JSObjectCallAsConstructorCallback callback = jsCast<JSCallbackConstructor*>(constructor)->callback();
    if (callback) {
        size_t argumentCount = exec->argumentCount();
        Vector<JSValueRef, 16> arguments;
        arguments.reserveInitialCapacity(argumentCount);
        for (size_t i = 0; i < argumentCount; ++i)
            arguments.uncheckedAppend(toRef(exec, exec->uncheckedArgument(i)));

        JSValueRef exception = 0;
        JSObjectRef result;
        {
            APICallbackShim callbackShim(exec);
            result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
        }
        if (exception)
            exec->vm().throwException(exec, toJS(exec, exception));
        // result must be a valid JSValue.
        if (!result)
            return throwVMTypeError(exec);
        return JSValue::encode(toJS(result));
    }
    
    return JSValue::encode(toJS(JSObjectMake(ctx, jsCast<JSCallbackConstructor*>(constructor)->classRef(), 0)));
}
Ejemplo n.º 15
0
void Java_com_vasco_digipass_sdk_smartfaceplugin_PluginImp_initNative(JNIEnv *env, jobject thiz,jlong jsContext,jlong envMap)
{
	long jscontextlong = (long)jsContext;
	DPPlugin* instance = DPPlugin::getInstance();
	instance->jsContext = (JSContextRef)jsContext;
	instance->envMap = (std::map<long,JNIEnv*>*)envMap;
	instance->pluginImpObject = env->NewGlobalRef(thiz);
    jclass clazz = env->GetObjectClass(thiz);
    jmethodID initMethod = env->GetMethodID(clazz,"init","(Ljava/lang/String;)V");
    jstring fingerprint = env->NewStringUTF(DBFINGERPRINT);
    env->CallVoidMethod(thiz,initMethod,fingerprint);
    env->DeleteLocalRef(fingerprint);
    instance->getBytes = env->GetMethodID(clazz,"getBytes","(Ljava/lang/String;)[B");
    instance->putBytes = env->GetMethodID(clazz,"putBytes","(Ljava/lang/String;Ljava/lang/String;[B)Z");
    instance->initializeRegistrationDataV2JavaFunction = env->GetMethodID(clazz,"initializeRegistrationDataV2","(Ljava/lang/String;[Z)Ljava/lang/String;");
    instance->decryptActivationDataJavaFunction = env->GetMethodID(clazz,"decryptActivationData","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Z)Ljava/lang/String;");
    instance->validateSharedDataChecksumJavaFunction = env->GetMethodID(clazz,"validateSharedDataChecksum","(Ljava/lang/String;[Z)Ljava/lang/String;");
    env->DeleteLocalRef(clazz);
    JSStringRef str = JSStringCreateWithUTF8CString("VASCO");
	JSClassRef classDef = JSClassCreate(&spjsdpplugin_def);
	JSObjectRef classObj = JSObjectMake(instance->jsContext, classDef, (void*)DPPlugin::getInstance());
	JSObjectSetProperty(instance->jsContext, JSContextGetGlobalObject(instance->jsContext), str, classObj, kJSPropertyAttributeNone, NULL);
    JSClassRelease(classDef);
	JSStringRelease(str);
}
Ejemplo n.º 16
0
 static JSObjectRef Make(JSContextRef context, Args_ &&... args) {
     Internal_ *internal(new Internal_(cy::Forward<Args_>(args)...));
     JSObjectRef object(JSObjectMake(context, Class_, internal));
     if (JSValueRef prototype = internal->GetPrototype(context))
         CYSetPrototype(context, object, prototype);
     return object;
 }
Ejemplo n.º 17
0
static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
{
    JSContextRef ctx = toRef(exec);
    JSObjectRef constructorRef = toRef(constructor);

    JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
    if (callback) {
        int argumentCount = static_cast<int>(args.size());
        Vector<JSValueRef, 16> arguments(argumentCount);
        for (int i = 0; i < argumentCount; i++)
            arguments[i] = toRef(exec, args.at(i));

        JSValueRef exception = 0;
        JSObjectRef result;
        {
            JSLock::DropAllLocks dropAllLocks(exec);
            result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
        }
        if (exception)
            exec->setException(toJS(exec, exception));
        return toJS(result);
    }
    
    return toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0));
}
Ejemplo n.º 18
0
static void window_object_cleared__(
	WebKitWebView  *wv,
	WebKitWebFrame *wf,
	JSGlobalContextRef ctx,
	gpointer        window_object,
	gpointer        user_data)
{
	const char* name0 = "z$";
	JSStringRef name = JSStringCreateWithUTF8CString(name0);

	JSObjectRef func;
	//func = JSObjectMakeFunctionWithCallback(ctx, name, zs__);
	{
		JSClassDefinition cd = kJSClassDefinitionEmpty;
		cd.className = name0;
		cd.callAsFunction = zs__;
		JSClassRef cr = JSClassCreate (&cd);
		func = JSObjectMake (ctx, cr, NULL);
	}

	JSObjectRef o = JSContextGetGlobalObject(ctx);
	JSObjectSetProperty(ctx, o, name, func, kJSPropertyAttributeNone, NULL);
	JSStringRelease(name);
	/*bool b=*/JSObjectSetPrivate(func, (void*)webkit_view___::from__(wv));
}
Ejemplo n.º 19
0
/* static */
Object Object::create(JSContextRef ctx) {
  JSObjectRef newObj = JSObjectMake(
      ctx,
      NULL, // create instance of default object class
      NULL); // no private data
  return Object(ctx, newObj);
}
Ejemplo n.º 20
0
static gboolean
gum_emit_thread (const GumThreadDetails * details,
                 gpointer user_data)
{
  GumJscMatchContext * mc = user_data;
  GumJscCore * core = mc->self->core;
  GumJscScope scope = GUM_JSC_SCOPE_INIT (core);
  JSContextRef ctx = mc->ctx;
  JSObjectRef thread;
  JSValueRef result;
  gboolean proceed;
  gchar * str;

  thread = JSObjectMake (ctx, NULL, NULL);
  _gumjs_object_set_uint (ctx, thread, "id", details->id);
  _gumjs_object_set_string (ctx, thread, "state",
      _gumjs_thread_state_to_string (details->state));
  _gumjs_object_set (ctx, thread, "context", _gumjs_cpu_context_new (ctx,
      (GumCpuContext *) &details->cpu_context, GUM_CPU_CONTEXT_READONLY, core));

  result = JSObjectCallAsFunction (ctx, mc->on_match, NULL, 1,
      (JSValueRef *) &thread, &scope.exception);
  _gum_jsc_scope_flush (&scope);

  proceed = TRUE;
  if (result != NULL && _gumjs_string_try_get (ctx, result, &str, NULL))
  {
    proceed = strcmp (str, "stop") != 0;
    g_free (str);
  }

  return proceed;
}
Ejemplo n.º 21
0
inline JSObjectRef RJSWrapObject(JSContextRef ctx, JSClassRef jsClass, T object, JSValueRef prototype = NULL) {
    JSObjectRef ref = JSObjectMake(ctx, jsClass, (void *)object);
    if (prototype) {
        JSObjectSetPrototype(ctx, ref, prototype);
    }
    return ref;
}
Ejemplo n.º 22
0
static JSObjectRef 
gtimer_construtor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, const JSValueRef argv[], JSValueRef* exception) 
{
    ScriptContext *sctx = scripts_get_context();
    GTimer *timer = g_timer_new();
    return JSObjectMake(ctx, sctx->classes[CLASS_TIMER], timer);
}
Ejemplo n.º 23
0
JSObjectRef makeEventSender(JSContextRef context, bool isTopFrame)
{
    if (isTopFrame) {
        dragMode = true;

        // Fly forward in time one second when the main frame loads. This will
        // ensure that when a test begins clicking in the same location as
        // a previous test, those clicks won't be interpreted as continuations
        // of the previous test's click sequences.
        timeOffset += 1000;

        lastMousePositionX = lastMousePositionY = 0;
        lastClickPositionX = lastClickPositionY = 0;
        lastClickTimeOffset = 0;
        lastClickButton = 0;
        buttonCurrentlyDown = 0;
        clickCount = 0;

        endOfQueue = 0;
        startOfQueue = 0;

        currentDragSourceContext = 0;
    }

    return JSObjectMake(context, getClass(context), 0);
}
Ejemplo n.º 24
0
void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
{
    JSRetainPtr<JSStringRef> layoutTestContollerStr(Adopt, JSStringCreateWithUTF8CString("layoutTestController"));
    ref();
    JSValueRef layoutTestContollerObject = JSObjectMake(context, getJSClass(), this);
    JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
}
Ejemplo n.º 25
0
JSValueRef ej_getNativeClass(JSContextRef ctx, JSObjectRef object, JSStringRef propertyNameJS, JSValueRef* exception) {
    size_t classNameSize = JSStringGetMaximumUTF8CStringSize(propertyNameJS);
    char* className = (char*)malloc(classNameSize);
    JSStringGetUTF8CString(propertyNameJS, className, classNameSize);

    JSObjectRef obj = NULL;
    NSString * fullClassName = new NSString();

    NSLOG("ej_getNativeClass : EJBinding%s", className);

    fullClassName->initWithFormat("EJBinding%s",className);
    EJBindingBase* pClass = (EJBindingBase*)NSClassFromString(fullClassName->getCString());
    if( pClass ) {
        obj = JSObjectMake( ctx, ej_constructorClass, (void *)pClass );
    } else {
        NSLOG("%s is NULL ... ", fullClassName->getCString());
    }

    if (obj)
    {
        NSLOG("constructor js-obj for %s", className);
    }

    free(className);
    fullClassName->autorelease();
    return obj ? obj : ej_global_undefined;
}
Ejemplo n.º 26
0
Archivo: shared.c Proyecto: vifino/dwb
JSObjectRef 
make_object_for_class(JSContextRef ctx, int iclass, GObject *o, gboolean protect)
{
    ScriptContext *sctx = scripts_get_context();
    if (sctx == NULL) 
        return JSValueToObject(ctx, NIL, NULL);

    JSObjectRef retobj = g_object_get_qdata(o, sctx->ref_quark);
    if (retobj != NULL) {
        goto finish;
    }

    retobj = JSObjectMake(ctx, sctx->classes[iclass], o);
    if (protect) 
    {
        g_object_set_qdata_full(o, sctx->ref_quark, retobj, (GDestroyNotify)object_destroy_cb);
        JSValueProtect(ctx, retobj);
    }
    else 
        g_object_set_qdata_full(o, sctx->ref_quark, retobj, NULL);

finish:
    scripts_release_context();
    return retobj;
}
Ejemplo n.º 27
0
 EJ_BIND_FUNCTION(EJBindingCanvas,getImageData, ctx, argc, argv) {
 	if( argc < 4 ) { return NULL; }
	
 	float
 		sx = JSValueToNumberFast(ctx, argv[0]),
 		sy = JSValueToNumberFast(ctx, argv[1]),
 		sw = JSValueToNumberFast(ctx, argv[2]),
 		sh = JSValueToNumberFast(ctx, argv[3]);
		
 	// Get the image data
 	//ejectaInstance->currentRenderingContext = renderingContext;
	ejectaInstance->setCurrentRenderingContext(renderingContext);
 	EJImageData * imageData = renderingContext->getImageData(sx,sy,sw,sh);
	
 	// Create the JS object
 	EJBindingImageData* tempData = new EJBindingImageData();
 	JSClassRef imageDataClass = EJApp::instance()->getJSClassForClass((EJBindingBase*)tempData);
 	tempData->autorelease();
 	JSObjectRef obj = JSObjectMake( ctx, imageDataClass, NULL );
 	JSValueProtect(ctx, obj);

 	// Create the native instance
 	EJBindingImageData * jsImageData = new EJBindingImageData(ctx,obj,imageData);
	
 	// Attach the native instance to the js object
 	JSObjectSetPrivate( obj, (void *)jsImageData );
 	JSValueUnprotect(ctx, obj);
 	return obj;
 }
Ejemplo n.º 28
0
static gboolean
gum_emit_malloc_range (const GumMallocRangeDetails * details,
                       gpointer user_data)
{
  GumJscMatchContext * mc = user_data;
  GumJscCore * core = mc->self->core;
  GumJscScope scope = GUM_JSC_SCOPE_INIT (core);
  JSContextRef ctx = mc->ctx;
  JSObjectRef range;
  JSValueRef result;
  gboolean proceed;
  gchar * str;

  range = JSObjectMake (ctx, NULL, NULL);
  _gumjs_object_set_pointer (ctx, range, "base",
      GSIZE_TO_POINTER (details->range->base_address), core);
  _gumjs_object_set_uint (ctx, range, "size", details->range->size);

  result = JSObjectCallAsFunction (ctx, mc->on_match, NULL, 1,
      (JSValueRef *) &range, &scope.exception);
  _gum_jsc_scope_flush (&scope);

  proceed = TRUE;
  if (result != NULL && _gumjs_string_try_get (ctx, result, &str, NULL))
  {
    proceed = strcmp (str, "stop") != 0;
    g_free (str);
  }

  return proceed;
}
Ejemplo n.º 29
0
void
_gum_jsc_process_init (GumJscProcess * self,
                       GumJscCore * core,
                       JSObjectRef scope)
{
  JSContextRef ctx = core->ctx;
  JSClassDefinition def;
  JSClassRef klass;
  JSObjectRef process;

  self->core = core;

  def = kJSClassDefinitionEmpty;
  def.className = "Process";
  def.staticFunctions = gumjs_process_functions;
  klass = JSClassCreate (&def);
  process = JSObjectMake (ctx, klass, self);
  JSClassRelease (klass);

  _gumjs_object_set_string (ctx, process, "arch", GUM_SCRIPT_ARCH);
  _gumjs_object_set_string (ctx, process, "platform", GUM_SCRIPT_PLATFORM);
  _gumjs_object_set_uint (ctx, process, "pageSize", gum_query_page_size ());
  _gumjs_object_set_uint (ctx, process, "pointerSize", GLIB_SIZEOF_VOID_P);

  _gumjs_object_set (ctx, scope, def.className, process);
}
	static void create(JSContextRef ctx, JSObjectRef global) {
		JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
		classDefinition.callAsConstructor = classConstructor;
		JSClassRef clsRef = JSClassCreate(&classDefinition);
		JSObjectRef classDef = JSObjectMake(ctx, clsRef, NULL);
		JSStringRef className = JSStringCreateWithUTF8CString("ManipulationDeltaEventHandler");
		JSObjectSetProperty(ctx, global, className, classDef, kJSPropertyAttributeNone, NULL);
	}