void ObjectWrapper::Key::del(JSContext* cx, JS::HandleObject o) { switch (_type) { case Type::Field: if (JS_DeleteProperty(cx, o, _field)) return; break; case Type::Index: if (JS_DeleteElement(cx, o, _idx)) return; break; case Type::Id: { JS::RootedId id(cx, _id); // For some reason JS_DeletePropertyById doesn't link if (JS_DeleteProperty(cx, o, IdWrapper(cx, id).toString().c_str())) return; break; } case Type::InternedString: { InternedStringId id(cx, _internedString); if (JS_DeleteProperty(cx, o, IdWrapper(cx, id).toString().c_str())) break; } } throwCurrentJSException(cx, ErrorCodes::InternalError, "Failed to delete value on a JSObject"); }
static JSObject * define_JavaPackage(JSContext *cx, JSObject *parent_obj, const char *obj_name, const char *path, int flags, int access) { JSObject *package_obj, *obj; JavaPackage_Private *package; jsval v; /* * Expose the same JSObject for Packages.java and java. * "java" will be defined during the java package initialization stage. * "Packages.java" will be lazily resolved by JavaPackage_resolve. * Ditto for sun and netscape. * See bugzilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=248409. */ if (!strcmp(obj_name, path) && (obj = JS_GetParent(cx, parent_obj)) && JS_LookupProperty(cx, obj, obj_name, &v) && !JSVAL_IS_PRIMITIVE(v)) { if (!JS_DefineProperty(cx, parent_obj, obj_name, v, NULL, NULL, JSPROP_PERMANENT | access)) { return NULL; } package_obj = JSVAL_TO_OBJECT(v); return package_obj; } package_obj = JS_DefineObject(cx, parent_obj, obj_name, &JavaPackage_class, 0, JSPROP_PERMANENT | access); if (!package_obj) return NULL; /* Attach private, native data to the JS object */ package = (JavaPackage_Private *)JS_malloc(cx, sizeof(JavaPackage_Private)); if (!package) { JS_DeleteProperty(cx, parent_obj, obj_name); return NULL; } JS_SetPrivate(cx, package_obj, (void *)package); if (path) package->path = JS_strdup(cx, path); else package->path = ""; package->flags = flags; /* Check for OOM */ if (!package->path) { JS_DeleteProperty(cx, parent_obj, obj_name); JS_free(cx, package); return NULL; } return package_obj; }
static JSObject * define_JavaPackage(JSContext *cx, JSObject *parent_obj, const char *obj_name, const char *path, int flags, int access) { JSObject *package_obj; JavaPackage_Private *package; package_obj = JS_DefineObject(cx, parent_obj, obj_name, &JavaPackage_class, 0, JSPROP_PERMANENT | access); if (!package_obj) return NULL; /* Attach private, native data to the JS object */ package = (JavaPackage_Private *)JS_malloc(cx, sizeof(JavaPackage_Private)); JS_SetPrivate(cx, package_obj, (void *)package); if (path) package->path = JS_strdup(cx, path); else package->path = ""; package->flags = flags; /* Check for OOM */ if (!package->path) { JS_DeleteProperty(cx, parent_obj, obj_name); JS_free(cx, package); return NULL; } return package_obj; }
native_netscape_javascript_JSObject_removeMember( JRIEnv* env, struct netscape_javascript_JSObject* self, struct java_lang_String * name) { JSContext *cx; JSObject *jso; JSSavedState saved; const char *cstr; if (!enterJS(env, self, &cx, &jso, &saved)) return; #ifdef JAVA if (! name || ! (cstr = JRI_GetStringPlatformChars(env, name, (const jbyte *) cx->charSetName, (jint) cx->charSetNameLength))) { /* FIXME this should be an error of some sort */ js_throwJSException(env, "illegal member name"); goto do_exit; } JS_DeleteProperty(cx, jso, cstr); #endif /* PR_LOG(Moja, debug, ("JSObject.removeMember(%s)\n", cstr)); */ do_exit: exitJS(env, self, cx, jso, &saved); return; }
/* * Do this all in a nested function evaluation so as (hopefully) not to get * screwed up by the conservative stack scanner when GCing. */ MOZ_NEVER_INLINE bool helper(JSObject* regexpProto) { CHECK(!regexpProto->inDictionaryMode()); // Verify the compartment's cached shape is being used by RegExp.prototype. const js::Shape* shape = regexpProto->lastProperty(); js::AutoShapeRooter root(cx, shape); for (js::Shape::Range r = shape; &r.front() != regexpProto->compartment()->initialRegExpShape; r.popFront()) { CHECK(!r.empty()); } JS::RootedValue v(cx, INT_TO_JSVAL(17)); CHECK(JS_SetProperty(cx, regexpProto, "foopy", v)); v = INT_TO_JSVAL(42); CHECK(JS_SetProperty(cx, regexpProto, "bunky", v)); CHECK(JS_DeleteProperty(cx, regexpProto, "foopy")); CHECK(regexpProto->inDictionaryMode()); const js::Shape* shape2 = regexpProto->lastProperty(); js::AutoShapeRooter root2(cx, shape2); js::Shape::Range r2 = shape2; while (!r2.empty()) { CHECK(&r2.front() != regexpProto->compartment()->initialRegExpShape); r2.popFront(); } return true; }
Eina_Bool unload_evas_object_params(JSContext *cx, JSObject *parent) { unsigned int i = 0; while (evas_object_params_function[i].name) JS_DeleteProperty(cx, parent, evas_object_params_function[i++].name); return EINA_TRUE; }
// called for lazily resolved properties, which should go away static JSBool get_and_destroy_resolved_property( JSContext* js_context, JSObject* obj, jsval id, jsval* retval) { PREPARE_JROOTS(js_context, 1); JROOT(id); char* name = JS_GetStringBytes(JSVAL_TO_STRING(id)); JCHECK(JS_DeleteProperty(js_context, obj, name)); JCHECK(get(js_context, obj, id, retval)); JRETURN; }
Eina_Bool unload_evas_const_binding(JSContext *cx, JSObject *parent) { unsigned int i = 0; while (evas_const_properties[i].name) JS_DeleteProperty(cx, parent, evas_const_properties[i++].name); return EINA_TRUE; }
static JSBool PreParse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { XMLGraphCallback *cb; if (!JS_DeleteProperty(cx, obj, "graph")) return JS_FALSE; cb = (XMLGraphCallback *)JS_GetPrivate(cx, obj); if (!cb) return JS_FALSE; cb->current = NULL; return JS_TRUE; }
void Engine::cleanupPredefinedObjects(JSContext *cx,JSObject *obj) { if ( JS_DeleteProperty(cx,obj,"response")==JS_FALSE ) { LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to cleanup predefined \"response\" object"); } if ( JS_DeleteProperty(cx,obj,"request")==JS_FALSE ) { LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to cleanup predefined \"request\" object"); } if ( JS_DeleteProperty(cx,obj,"server")==JS_FALSE ) { LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to cleanup predefined \"server\" object"); } if ( JS_DeleteProperty(cx,obj,"session")==JS_FALSE ) { LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to cleanup predefined \"session\" object"); } if ( JS_DeleteProperty(cx,obj,"site")==JS_FALSE ) { LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to cleanup predefined \"site\" object"); } }
/* An import failed. Delete the property pointing to the import * from the parent namespace. In complicated situations this might * not be sufficient to get us fully back to a sane state. If: * * - We import module A * - module A imports module B * - module B imports module A, storing a reference to the current * module A module object * - module A subsequently throws an exception * * Then module B is left imported, but the imported module B has * a reference to the failed module A module object. To handle this * we could could try to track the entire "import operation" and * roll back *all* modifications made to the namespace objects. * It's not clear that the complexity would be worth the small gain * in robustness. (You can still come up with ways of defeating * the attempt to clean up.) */ static void cancel_import(JSContext *context, JSObject *obj, const char *name) { gjs_debug(GJS_DEBUG_IMPORTER, "Cleaning up from failed import of '%s'", name); if (!JS_DeleteProperty(context, obj, name)) { gjs_debug(GJS_DEBUG_IMPORTER, "Failed to delete '%s' in importer", name); } }
static Eina_Bool module_close(Elixir_Module *em, JSContext *cx) { void **tmp; unsigned int i = 0; if (!em->data) return EINA_FALSE; elixir_eet_shutdown(cx, em->data); tmp = &em->data; while (eet_functions[i].name) JS_DeleteProperty(cx, *((JSObject**) tmp), eet_functions[i++].name); elixir_object_unregister(cx, (JSObject**) tmp); em->data = NULL; return EINA_TRUE; }
static Eina_Bool _egueb_script_js_sm_scripter_script_run_listener(void *prv, void *s, Egueb_Dom_Event *ev) { Egueb_Script_Js_Sm_Scripter *thiz = prv; Egueb_Script_Js_Sm_Scripter_Script *script = s; JSObject *evt; jsval rval; JSBool ret; Ender_Item *i; /* TODO create 'this' in case it does not exist yet */ /* set 'evt' as part of global */ i = egueb_dom_event_item_get(ev); evt = ender_js_sm_instance_new(thiz->cx, i, egueb_dom_event_ref(ev)); JS_DefineProperty(thiz->cx, thiz->global, "evt", OBJECT_TO_JSVAL(evt), NULL, NULL, JSPROP_READONLY); ret = JS_ExecuteScript(thiz->cx, thiz->global, script->obj, &rval); /* remove the evt */ JS_DeleteProperty(thiz->cx, thiz->global, "evt"); return ret; }
bool rs::jsapi::Global::DeleteFunction(Context& cx, const char* name) { JSAutoRequest ar(cx); return JS_DeleteProperty(cx, cx.getGlobal(), name); }