Example #1
0
bool
document_resolve(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned flags,
                 JS::MutableHandleObject objp)
{
    // If id is "all", resolve document.all=true.
    JS::RootedValue v(cx);
    if (!JS_IdToValue(cx, id, &v))
        return false;
    if (JSVAL_IS_STRING(v)) {
        JSString *str = JSVAL_TO_STRING(v);
        JSFlatString *flatStr = JS_FlattenString(cx, str);
        if (!flatStr)
            return false;
        if (JS_FlatStringEqualsAscii(flatStr, "all")) {
            JS::Rooted<JSObject*> docAll(cx,
                                         JS_NewObject(cx, &DocumentAllClass, JS::NullPtr(), JS::NullPtr()));
            if (!docAll)
                return false;
            JS::Rooted<JS::Value> allValue(cx, ObjectValue(*docAll));
            bool ok = JS_DefinePropertyById(cx, obj, id, allValue, nullptr, nullptr, 0);
            objp.set(ok ? obj.get() : nullptr);
            return ok;
        }
    }
    objp.set(nullptr);
    return true;
}
CEXPORT bool def_timestep_image_map_set_width(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) {
	JS_BeginRequest(cx);
	timestep_image_map *thiz = (timestep_image_map*)JS_GetPrivate(obj.get());
	if (thiz) {
		
		thiz->width = vp.toInt32();
		
	}
	JS_EndRequest(cx);
	return true;
}
CEXPORT bool def_timestep_image_map_get_y(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) {
	JS_BeginRequest(cx);
	timestep_image_map *thiz = (timestep_image_map*)JS_GetPrivate(obj.get());
	if (thiz) {
		
		vp.setInt32(thiz->y);
		
	}
	JS_EndRequest(cx);
	return true;
}
Example #4
0
static JSBool js_cocos2dx_extension_WebSocket_get_readyState(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
{
    JSObject* jsobj = obj.get();
	js_proxy_t *proxy = jsb_get_js_proxy(jsobj);
	WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL);
	JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
    
    if (cobj) {
        vp.set(INT_TO_JSVAL((int)cobj->getReadyState()));
        return JS_TRUE;
    } else {
        JS_ReportError(cx, "Error: WebSocket instance is invalid.");
        return JS_FALSE;
    }
}
Example #5
0
static bool _js_get_SIOClient_tag(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
{
    CCLOG("JSB SocketIO.getTag method called");
    JSObject* jsobj = obj.get();
    js_proxy_t *proxy = jsb_get_js_proxy(jsobj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
    
    if (cobj) {
        vp.set(std_string_to_jsval(cx, cobj->getTag()));
        return true;
    } else {
        JS_ReportError(cx, "Error: SocketIO instance is invalid.");
        return false;
    }

}
Example #6
0
void
gjs_define_param_class(JSContext       *context,
                       JS::HandleObject in_object)
{
    const char *constructor_name;
    JS::RootedObject prototype(context), constructor(context);
    GIObjectInfo *info;

    constructor_name = "ParamSpec";

    if (!gjs_init_class_dynamic(context, in_object, nullptr, "GObject",
                                constructor_name,
                                &gjs_param_class,
                                gjs_param_constructor, 0,
                                /* props of prototype */
                                &gjs_param_proto_props[0],
                                /* funcs of prototype */
                                &gjs_param_proto_funcs[0],
                                /* props of constructor, MyConstructor.myprop */
                                NULL,
                                /* funcs of constructor, MyConstructor.myfunc() */
                                gjs_param_constructor_funcs,
                                &prototype,
                                &constructor)) {
        g_error("Can't init class %s", constructor_name);
    }

    JS::RootedObject gtype_obj(context,
        gjs_gtype_create_gtype_wrapper(context, G_TYPE_PARAM));
    JS_DefineProperty(context, constructor, "$gtype", gtype_obj, JSPROP_PERMANENT);

    info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), G_TYPE_PARAM);
    gjs_object_define_static_methods(context, constructor, G_TYPE_PARAM, info);
    g_base_info_unref( (GIBaseInfo*) info);

    gjs_debug(GJS_DEBUG_GPARAM, "Defined class %s prototype is %p class %p in object %p",
              constructor_name, prototype.get(), JS_GetClass(prototype),
              in_object.get());
}
CEXPORT bool def_timestep_image_map_set_url(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) {
	JS_BeginRequest(cx);
	timestep_image_map *thiz = (timestep_image_map*)JS_GetPrivate(obj.get());
	if (thiz) {
		
		if (vp.isString()) {
	JSString *jstr = vp.toString();

	JSTR_TO_CSTR_PERSIST(cx, jstr, cstr);

	if (thiz->url) {
		free(thiz->url);
	}

	thiz->url = cstr;
}

		
	}
	JS_EndRequest(cx);
	return true;
}