/* define properties that JS Error() expose, such as fileName, lineNumber and stack */ static void define_error_properties(JSContext *context, JSObject *obj) { jsid stack_name, filename_name, linenumber_name; jsval stack, fileName, lineNumber; if (!gjs_context_get_frame_info (context, &stack, &fileName, &lineNumber)) return; stack_name = gjs_runtime_get_const_string(JS_GetRuntime(context), GJS_STRING_STACK); filename_name = gjs_runtime_get_const_string(JS_GetRuntime(context), GJS_STRING_FILENAME); linenumber_name = gjs_runtime_get_const_string(JS_GetRuntime(context), GJS_STRING_LINE_NUMBER); JS_DefinePropertyById(context, obj, stack_name, stack, NULL, NULL, JSPROP_ENUMERATE); JS_DefinePropertyById(context, obj, filename_name, fileName, NULL, NULL, JSPROP_ENUMERATE); JS_DefinePropertyById(context, obj, linenumber_name, lineNumber, NULL, NULL, JSPROP_ENUMERATE); }
void ObjectWrapper::Key::define(JSContext* cx, JS::HandleObject o, JS::HandleValue value, unsigned attrs) { switch (_type) { case Type::Field: if (JS_DefineProperty(cx, o, _field, value, attrs)) return; break; case Type::Index: if (JS_DefineElement(cx, o, _idx, value, attrs)) return; break; case Type::Id: { JS::RootedId id(cx, _id); if (JS_DefinePropertyById(cx, o, id, value, attrs)) return; break; } case Type::InternedString: { InternedStringId id(cx, _internedString); if (JS_DefinePropertyById(cx, o, id, value, attrs)) return; break; } } throwCurrentJSException(cx, ErrorCodes::InternalError, "Failed to define value on a JSObject"); }
bool doResolve(JSObject *obj, jsid id, uintN flags, JSObject **objp) { CHECK_EQUAL(resolveExitCount, 0); AutoIncrCounters incr(this); CHECK_EQUAL(obj, obj1 || obj == obj2); CHECK(JSID_IS_STRING(id)); JSFlatString *str = JS_FlattenString(cx, JSID_TO_STRING(id)); CHECK(str); jsval v; if (JS_FlatStringEqualsAscii(str, "x")) { if (obj == obj1) { /* First resolve hook invocation. */ CHECK_EQUAL(resolveEntryCount, 1); EVAL("obj2.y = true", &v); CHECK_SAME(v, JSVAL_TRUE); CHECK(JS_DefinePropertyById(cx, obj, id, JSVAL_FALSE, NULL, NULL, 0)); *objp = obj; return true; } if (obj == obj2) { CHECK_EQUAL(resolveEntryCount, 4); *objp = NULL; return true; } } else if (JS_FlatStringEqualsAscii(str, "y")) { if (obj == obj2) { CHECK_EQUAL(resolveEntryCount, 2); CHECK(JS_DefinePropertyById(cx, obj, id, JSVAL_NULL, NULL, NULL, 0)); EVAL("obj1.x", &v); CHECK(JSVAL_IS_VOID(v)); EVAL("obj1.y", &v); CHECK_SAME(v, JSVAL_ZERO); *objp = obj; return true; } if (obj == obj1) { CHECK_EQUAL(resolveEntryCount, 3); EVAL("obj1.x", &v); CHECK(JSVAL_IS_VOID(v)); EVAL("obj1.y", &v); CHECK(JSVAL_IS_VOID(v)); EVAL("obj2.y", &v); CHECK(JSVAL_IS_NULL(v)); EVAL("obj2.x", &v); CHECK(JSVAL_IS_VOID(v)); EVAL("obj1.y = 0", &v); CHECK_SAME(v, JSVAL_ZERO); *objp = obj; return true; } } CHECK(false); return false; }
bool doResolve(JS::HandleObject obj, JS::HandleId id, bool* resolvedp) { CHECK_EQUAL(resolveExitCount, 0); AutoIncrCounters incr(this); CHECK(obj == obj1 || obj == obj2); CHECK(JSID_IS_STRING(id)); JSFlatString* str = JS_FlattenString(cx, JSID_TO_STRING(id)); CHECK(str); JS::RootedValue v(cx); if (JS_FlatStringEqualsAscii(str, "x")) { if (obj == obj1) { /* First resolve hook invocation. */ CHECK_EQUAL(resolveEntryCount, 1); EVAL("obj2.y = true", &v); CHECK(v.isTrue()); CHECK(JS_DefinePropertyById(cx, obj, id, JS::FalseHandleValue, JSPROP_RESOLVING)); *resolvedp = true; return true; } if (obj == obj2) { CHECK_EQUAL(resolveEntryCount, 4); *resolvedp = false; return true; } } else if (JS_FlatStringEqualsAscii(str, "y")) { if (obj == obj2) { CHECK_EQUAL(resolveEntryCount, 2); CHECK(JS_DefinePropertyById(cx, obj, id, JS::NullHandleValue, JSPROP_RESOLVING)); EVAL("obj1.x", &v); CHECK(v.isUndefined()); EVAL("obj1.y", &v); CHECK(v.isInt32(0)); *resolvedp = true; return true; } if (obj == obj1) { CHECK_EQUAL(resolveEntryCount, 3); EVAL("obj1.x", &v); CHECK(v.isUndefined()); EVAL("obj1.y", &v); CHECK(v.isUndefined()); EVAL("obj2.y", &v); CHECK(v.isNull()); EVAL("obj2.x", &v); CHECK(v.isUndefined()); EVAL("obj1.y = 0", &v); CHECK(v.isInt32(0)); *resolvedp = true; return true; } } CHECK(false); return false; }
bool doResolve(JSHandleObject obj, JSHandleId id, unsigned flags, JSMutableHandleObject objp) { CHECK_EQUAL(resolveExitCount, 0); AutoIncrCounters incr(this); CHECK_EQUAL(obj, obj1 || obj == obj2); CHECK(JSID_IS_STRING(id)); JSFlatString *str = JS_FlattenString(cx, JSID_TO_STRING(id)); CHECK(str); JS::RootedValue v(cx); if (JS_FlatStringEqualsAscii(str, "x")) { if (obj == obj1) { /* First resolve hook invocation. */ CHECK_EQUAL(resolveEntryCount, 1); EVAL("obj2.y = true", v.address()); CHECK_SAME(v, JSVAL_TRUE); CHECK(JS_DefinePropertyById(cx, obj, id, JSVAL_FALSE, NULL, NULL, 0)); objp.set(obj); return true; } if (obj == obj2) { CHECK_EQUAL(resolveEntryCount, 4); objp.set(NULL); return true; } } else if (JS_FlatStringEqualsAscii(str, "y")) { if (obj == obj2) { CHECK_EQUAL(resolveEntryCount, 2); CHECK(JS_DefinePropertyById(cx, obj, id, JSVAL_NULL, NULL, NULL, 0)); EVAL("obj1.x", v.address()); CHECK(JSVAL_IS_VOID(v)); EVAL("obj1.y", v.address()); CHECK_SAME(v, JSVAL_ZERO); objp.set(obj); return true; } if (obj == obj1) { CHECK_EQUAL(resolveEntryCount, 3); EVAL("obj1.x", v.address()); CHECK(JSVAL_IS_VOID(v)); EVAL("obj1.y", v.address()); CHECK(JSVAL_IS_VOID(v)); EVAL("obj2.y", v.address()); CHECK(JSVAL_IS_NULL(v)); EVAL("obj2.x", v.address()); CHECK(JSVAL_IS_VOID(v)); EVAL("obj1.y = 0", v.address()); CHECK_SAME(v, JSVAL_ZERO); objp.set(obj); return true; } } CHECK(false); return false; }
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; }
JSBool gjs_define_root_importer(JSContext *context, JSObject *in_object) { jsval importer; JSBool success; jsid imports_name; success = JS_FALSE; JS_BeginRequest(context); importer = gjs_get_global_slot(context, GJS_GLOBAL_SLOT_IMPORTS); imports_name = gjs_runtime_get_const_string(JS_GetRuntime(context), GJS_STRING_IMPORTS); if (!JS_DefinePropertyById(context, in_object, imports_name, importer, NULL, NULL, GJS_MODULE_PROP_FLAGS)) { gjs_debug(GJS_DEBUG_IMPORTER, "DefineProperty imports on %p failed", in_object); goto fail; } success = JS_TRUE; fail: JS_EndRequest(context); return success; }
bool document_resolve(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolvedp) { // If id is "all", resolve document.all=true. JS::RootedValue v(cx); if (!JS_IdToValue(cx, id, &v)) return false; if (v.isString()) { JSString *str = v.toString(); 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, JS::ObjectValue(*docAll)); if (!JS_DefinePropertyById(cx, obj, id, allValue, 0)) return false; *resolvedp = true; return true; } } *resolvedp = false; return true; }
/* PRBool resolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsval id); */ NS_IMETHODIMP nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, jsid id, PRUint32 flags, JSObject * *objp, PRBool *_retval) { XPCCallContext ccx(JS_CALLER, cx); AutoMarkingNativeInterfacePtr iface(ccx); const nsIID* iid; mInfo->GetIIDShared(&iid); iface = XPCNativeInterface::GetNewOrUsed(ccx, iid); if(!iface) return NS_OK; XPCNativeMember* member = iface->FindMember(id); if(member && member->IsConstant()) { jsval val; if(!member->GetConstantValue(ccx, iface, &val)) return NS_ERROR_OUT_OF_MEMORY; *objp = obj; *_retval = JS_DefinePropertyById(cx, obj, id, val, nsnull, nsnull, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); } return NS_OK; }
static JSObject * load_module_init(JSContext *context, JSObject *in_object, std::string &full_path) { JSObject *module_obj; JSBool found; jsid module_init_name; /* First we check if js module has already been loaded */ module_init_name = gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT); if (JS_HasPropertyById(context, in_object, module_init_name, &found) && found) { jsval module_obj_val; if (JS_GetPropertyById(context, in_object, module_init_name, &module_obj_val)) { return JSVAL_TO_OBJECT(module_obj_val); } } module_obj = create_module_object (context); if (!import_file (context, "__init__", full_path, module_obj)) std::cout << "error\n"; if (!JS_DefinePropertyById(context, in_object, module_init_name, OBJECT_TO_JSVAL(module_obj), NULL, NULL, GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) std::cout << "error\n"; return module_obj; }
JSBool gjs_define_root_importer_object(JSContext *context, JS::HandleObject in_object, JS::HandleObject root_importer) { JSBool success; jsid imports_name; success = JS_FALSE; JS_BeginRequest(context); JS::RootedValue importer (JS_GetRuntime(context), OBJECT_TO_JSVAL(root_importer)); imports_name = gjs_context_get_const_string(context, GJS_STRING_IMPORTS); if (!JS_DefinePropertyById(context, in_object, imports_name, importer, NULL, NULL, GJS_MODULE_PROP_FLAGS)) { gjs_debug(GJS_DEBUG_IMPORTER, "DefineProperty imports on %p failed", (JSObject *) in_object); goto fail; } success = JS_TRUE; fail: JS_EndRequest(context); return success; }
NS_IMETHODIMP nsJetpack::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval) { if (JSVAL_IS_STRING(id) && strncmp(JS_GetStringBytes(JSVAL_TO_STRING(id)), "get", 3) == 0) { JSFunction *get = JS_NewFunction(cx, getEndpoint, 0, 0, JS_GetParent(cx, obj), "get"); if (!get) { JS_ReportOutOfMemory(cx); *_retval = PR_FALSE; return NS_OK; } JSObject *getObj = JS_GetFunctionObject(get); jsid idid; *objp = obj; *_retval = (JS_ValueToId(cx, id, &idid) && JS_DefinePropertyById(cx, obj, idid, OBJECT_TO_JSVAL(getObj), nsnull, nsnull, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)); return NS_OK; } *objp = nsnull; *_retval = PR_TRUE; return NS_OK; }
DEFINE_STD_ITERATOR() { JL_DEFINE_ARGS; JS::RootedObject itObj(cx, jl::newObject(cx)); JL_ASSERT_ALLOC( itObj ); JL_CHK( JS_DefineFunctionById(cx, itObj, JLID(cx, next), _stdIteratorNext, 0, 0) ); JL_CHK( JS_DefinePropertyById(cx, itObj, JLID(cx, source), JL_OBJVAL, NULL, NULL, 0) ); JL_RVAL.setObject(*itObj); return true; JL_BAD; }
void OIDInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) { JS::RootedValue undef(cx); undef.setUndefined(); if (!JS_DefinePropertyById(cx, proto, getScope(cx)->getInternedStringId(InternedString::str), undef, JSPROP_ENUMERATE | JSPROP_SHARED, smUtils::wrapConstrainedMethod<Functions::getter, true, OIDInfo>, nullptr)) { uasserted(ErrorCodes::JSInterpreterFailure, "Failed to JS_DefinePropertyById"); } }
PLDHashOperator StatementEnumerator(TelemetryImpl::SlowSQLEntryType *entry, void *arg) { EnumeratorArgs *args = static_cast<EnumeratorArgs *>(arg); const nsACString &statement = entry->GetKey(); jsval hitCount = UINT_TO_JSVAL(entry->mData.hitCount); jsval totalTime = UINT_TO_JSVAL(entry->mData.totalTime); args->statementIndex++; JSObject *hitsAndTimeObj = JS_NewArrayObject(args->cx, 2, nsnull); if (!hitsAndTimeObj || !JS_SetElement(args->cx, hitsAndTimeObj, 0, &hitCount) || !JS_SetElement(args->cx, hitsAndTimeObj, 1, &totalTime)) return PL_DHASH_STOP; jsid propertyId = INT_TO_JSID(args->statementIndex); JSBool success = JS_DefinePropertyById(args->cx, args->statsObj, INT_TO_JSID(args->statementIndex), OBJECT_TO_JSVAL(hitsAndTimeObj), NULL, NULL, JSPROP_ENUMERATE); if (!success) return PL_DHASH_STOP; JSString *string = JS_NewStringCopyN(args->cx, statement.BeginReading(), statement.Length()); if (!string) return PL_DHASH_STOP; success = JS_DefinePropertyById(args->cx, args->statementsObj, INT_TO_JSID(args->statementIndex), STRING_TO_JSVAL(string), NULL, NULL, JSPROP_ENUMERATE); if (!success) return PL_DHASH_STOP; return PL_DHASH_NEXT; }
bool ScriptInterface::SetPropertyInt_(jsval obj, int name, jsval value, bool constant, bool enumerate) { uintN attrs = 0; if (constant) attrs |= JSPROP_READONLY | JSPROP_PERMANENT; if (enumerate) attrs |= JSPROP_ENUMERATE; if (! JSVAL_IS_OBJECT(obj)) return false; JSObject* object = JSVAL_TO_OBJECT(obj); if (! JS_DefinePropertyById(m->m_cx, object, INT_TO_JSID(name), value, NULL, NULL, attrs)) return false; return true; }
bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) { JSAutoRequest rq(m->m_cx); uint attrs = 0; if (constant) attrs |= JSPROP_READONLY | JSPROP_PERMANENT; if (enumerate) attrs |= JSPROP_ENUMERATE; if (!obj.isObject()) return false; JS::RootedObject object(m->m_cx, &obj.toObject()); if (! JS_DefinePropertyById(m->m_cx, object, INT_TO_JSID(name), value, NULL, NULL, attrs)) return false; return true; }
static JSBool ReifyPropertyOps(JSContext *cx, JSObject *obj, jsval idval, jsid interned_id, const char *name, JSPropertyOp getter, JSPropertyOp setter, JSObject **getterobjp, JSObject **setterobjp) { // Generate both getter and setter and stash them in the prototype. jsval roots[2] = { JSVAL_NULL, JSVAL_NULL }; JSAutoTempValueRooter tvr(cx, 2, roots); uintN attrs = JSPROP_SHARED; JSObject *getterobj; if(getter) { getterobj = GeneratePropertyOp(cx, obj, idval, 0, name, getter); if(!getterobj) return JS_FALSE; roots[0] = OBJECT_TO_JSVAL(getterobj); attrs |= JSPROP_GETTER; } else getterobj = nsnull; JSObject *setterobj; if (setter) { setterobj = GeneratePropertyOp(cx, obj, idval, 1, name, setter); if(!setterobj) return JS_FALSE; roots[1] = OBJECT_TO_JSVAL(setterobj); attrs |= JSPROP_SETTER; } else setterobj = nsnull; if(getterobjp) *getterobjp = getterobj; if(setterobjp) *setterobjp = setterobj; return JS_DefinePropertyById(cx, obj, interned_id, JSVAL_VOID, JS_DATA_TO_FUNC_PTR(JSPropertyOp, getterobj), JS_DATA_TO_FUNC_PTR(JSPropertyOp, setterobj), attrs); }
static JSBool XPC_COW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { obj = GetWrapper(obj); jsval resolving; if (!JS_GetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, &resolving)) { return JS_FALSE; } if (HAS_FLAGS(resolving, FLAG_RESOLVING)) { // Allow us to define a property on ourselves. return JS_TRUE; } // Someone's adding a property to us. We need to protect ourselves from // getters and setters. JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } jsid interned_id; JSPropertyDescriptor desc; if (!JS_ValueToId(cx, id, &interned_id) || !XPCWrapper::GetPropertyAttrs(cx, obj, interned_id, JSRESOLVE_QUALIFIED, JS_TRUE, &desc)) { return JS_FALSE; } NS_ASSERTION(desc.obj == obj, "The JS engine lies!"); if (desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) { // Only chrome is allowed to add getters or setters to our object. if (!AllowedToAct(cx, id)) { return JS_FALSE; } } return XPC_COW_RewrapForChrome(cx, obj, vp) && JS_DefinePropertyById(cx, wrappedObj, interned_id, *vp, desc.getter, desc.setter, desc.attrs); }
bool DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, Handle<PropertyDescriptor> desc, JS::ObjectOpResult &result, bool *defined) const { if (xpc::WrapperFactory::IsXrayWrapper(proxy)) { return result.succeed(); } JS::Rooted<JSObject*> expando(cx, EnsureExpandoObject(cx, proxy)); if (!expando) { return false; } if (!JS_DefinePropertyById(cx, expando, id, desc, result)) { return false; } *defined = true; return true; }
JSBool document_resolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags, JSObject **objp) { // If id is "all", and we're not detecting, resolve document.all=true. jsvalRoot v(cx); if (!JS_IdToValue(cx, id, v.addr())) return false; if (JSVAL_IS_STRING(v.value())) { JSString *str = JSVAL_TO_STRING(v.value()); JSFlatString *flatStr = JS_FlattenString(cx, str); if (!flatStr) return false; if (JS_FlatStringEqualsAscii(flatStr, "all") && !(flags & JSRESOLVE_DETECTING)) { JSBool ok = JS_DefinePropertyById(cx, obj, id, JSVAL_TRUE, NULL, NULL, 0); *objp = ok ? obj.value() : NULL; return ok; } } *objp = NULL; return true; }
static JSObject * load_module_init(JSContext *context, JSObject *in_object, const char *full_path) { JSObject *module_obj; JSBool found; jsid module_init_name; GFile *file; /* First we check if js module has already been loaded */ module_init_name = gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT); if (!is_extension_module (full_path) && JS_HasPropertyById(context, in_object, module_init_name, &found) && found) { jsval module_obj_val; if (JS_GetPropertyById(context, in_object, module_init_name, &module_obj_val)) { return JSVAL_TO_OBJECT(module_obj_val); } } module_obj = create_module_object (context); file = g_file_new_for_commandline_arg(full_path); if (!import_file (context, "__init__", file, module_obj)) goto out; if (!JS_DefinePropertyById(context, in_object, module_init_name, OBJECT_TO_JSVAL(module_obj), NULL, NULL, GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) goto out; out: g_object_unref (file); return module_obj; }
bool DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JSPropertyDescriptor* desc) { if ((desc->attrs & JSPROP_GETTER) && desc->setter == JS_StrictPropertyStub) { return JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING | JSREPORT_STRICT | JSREPORT_STRICT_MODE_ERROR, js_GetErrorMessage, NULL, JSMSG_GETTER_ONLY); } if (xpc::WrapperFactory::IsXrayWrapper(proxy)) { return true; } JSObject* expando = EnsureExpandoObject(cx, proxy); if (!expando) { return false; } return JS_DefinePropertyById(cx, expando, id, desc->value, desc->getter, desc->setter, desc->attrs); }
static JSObject * load_module_init(JSContext *context, JSObject *in_object, const char *full_path) { char *script; gsize script_len; jsval script_retval; JSObject *module_obj; GError *error; JSBool found; jsid module_init_name; /* First we check if js module has already been loaded */ module_init_name = gjs_runtime_get_const_string(JS_GetRuntime(context), GJS_STRING_MODULE_INIT); if (JS_HasPropertyById(context, in_object, module_init_name, &found) && found) { jsval module_obj_val; if (JS_GetPropertyById(context, in_object, module_init_name, &module_obj_val)) { return JSVAL_TO_OBJECT(module_obj_val); } } module_obj = JS_NewObject(context, NULL, NULL, NULL); if (module_obj == NULL) { return JS_FALSE; } /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we * can't just pass in the global as the parent */ JS_SetParent(context, module_obj, gjs_get_import_global (context)); /* Define module in importer for future use and to avoid module_obj * object to be garbage collected during the evaluation of the script */ JS_DefinePropertyById(context, in_object, module_init_name, OBJECT_TO_JSVAL(module_obj), NULL, NULL, GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT); script_len = 0; error = NULL; if (!g_file_get_contents(full_path, &script, &script_len, &error)) { if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) && !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) && !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) gjs_throw_g_error(context, error); else g_error_free(error); return NULL; } g_assert(script != NULL); gjs_debug(GJS_DEBUG_IMPORTER, "Importing %s", full_path); if (!JS_EvaluateScript(context, module_obj, script, script_len, full_path, 1, /* line number */ &script_retval)) { g_free(script); /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception * would be left set after the evaluate and not go to the error * reporter function. */ if (JS_IsExceptionPending(context)) { gjs_debug(GJS_DEBUG_IMPORTER, "Module " MODULE_INIT_FILENAME " left an exception set"); gjs_log_and_keep_exception(context); } else { gjs_throw(context, "JS_EvaluateScript() returned FALSE but did not set exception"); } return NULL; } g_free(script); return module_obj; }