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; }
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; } }
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; } }
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; }
js::UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value) { JS_ASSERT(obj->isNative()); JS_ASSERT(index < obj->getDenseInitializedLength()); obj->setDenseElementWithType(cx, index, value); }
JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda) { assertSameCompartment(cx, obj); uint32_t i = 0; JSPropertyDesc *pd = nullptr; if (obj->is<DebugScopeObject>()) { AutoIdVector props(cx); if (!Proxy::enumerate(cx, obj, props)) return false; pd = cx->pod_calloc<JSPropertyDesc>(props.length()); if (!pd) return false; for (i = 0; i < props.length(); ++i) { pd[i].id = JSVAL_NULL; pd[i].value = JSVAL_NULL; if (!AddValueRoot(cx, &pd[i].id, nullptr)) goto bad; pd[i].id = IdToValue(props[i]); if (!AddValueRoot(cx, &pd[i].value, nullptr)) goto bad; if (!Proxy::get(cx, obj, obj, props.handleAt(i), MutableHandleValue::fromMarkedLocation(&pd[i].value))) goto bad; } pda->length = props.length(); pda->array = pd; return true; } const Class *clasp; clasp = obj->getClass(); if (!obj->isNative() || (clasp->flags & JSCLASS_NEW_ENUMERATE)) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_DESCRIBE_PROPS, clasp->name); return false; } if (!clasp->enumerate(cx, obj)) return false; /* Return an empty pda early if obj has no own properties. */ if (obj->nativeEmpty()) { pda->length = 0; pda->array = nullptr; return true; } pd = cx->pod_malloc<JSPropertyDesc>(obj->propertyCount()); if (!pd) return false; { Shape::Range<CanGC> r(cx, obj->lastProperty()); RootedShape shape(cx); for (; !r.empty(); r.popFront()) { pd[i].id = JSVAL_NULL; pd[i].value = JSVAL_NULL; pd[i].alias = JSVAL_NULL; if (!AddValueRoot(cx, &pd[i].id, nullptr)) goto bad; if (!AddValueRoot(cx, &pd[i].value, nullptr)) goto bad; shape = const_cast<Shape *>(&r.front()); if (!GetPropertyDesc(cx, obj, shape, &pd[i])) goto bad; if ((pd[i].flags & JSPD_ALIAS) && !AddValueRoot(cx, &pd[i].alias, nullptr)) goto bad; if (++i == obj->propertyCount()) break; } } pda->length = i; pda->array = pd; return true; bad: pda->length = i + 1; pda->array = pd; JS_PutPropertyDescArray(cx, pda); return false; }
js::SetCompartmentValidAccessPtr(JSContext* cx, JS::HandleObject global, bool* accessp) { global->compartment()->setValidAccessPtr(accessp); }