void CManageVariableDlg::OnBnClickedAdd() { CAddVariableDlg Dlg; Dlg.Name.Format("Variable %d", m_List.GetItemCount() + 1); if (Dlg.DoModal() == IDOK) { if (VariableNameExists(Dlg.Name)) MessageBox(CString("The private variable name '") + Dlg.Name + "' already exists. Please choose a unique name.", "Private variables", MB_OK | MB_ICONEXCLAMATION); else { m_List.InsertItem(m_List.GetItemCount(), Dlg.Name, 0); m_List.SetItemText(m_List.GetItemCount() - 1, 1, GetTypeName(Dlg.Type)); m_List.SetItemText(m_List.GetItemCount() - 1, 2, Dlg.Value); // Add the new variable to the object type int id = pType->VariableID++; pType->m_PrivateValues.push_back(PrivateValue(Dlg.Name, Dlg.Type, id)); // Add the new variable to the corresponding instance values PrivateVariableInstanceAdder updater(id, Dlg.Value); ForEachObjectInstance(pType, layout->application, updater); } } }
void SavedFrame::initFromLookup(Lookup &lookup) { JS_ASSERT(lookup.source); JS_ASSERT(getReservedSlot(JSSLOT_SOURCE).isUndefined()); setReservedSlot(JSSLOT_SOURCE, StringValue(lookup.source)); setReservedSlot(JSSLOT_LINE, NumberValue(lookup.line)); setReservedSlot(JSSLOT_COLUMN, NumberValue(lookup.column)); setReservedSlot(JSSLOT_FUNCTIONDISPLAYNAME, lookup.functionDisplayName ? StringValue(lookup.functionDisplayName) : NullValue()); setReservedSlot(JSSLOT_PARENT, ObjectOrNullValue(lookup.parent)); setReservedSlot(JSSLOT_PRIVATE_PARENT, PrivateValue(lookup.parent)); JS_ASSERT(getReservedSlot(JSSLOT_PRINCIPALS).isUndefined()); if (lookup.principals) JS_HoldPrincipals(lookup.principals); setReservedSlot(JSSLOT_PRINCIPALS, PrivateValue(lookup.principals)); }
bool Library::Close(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); JSObject* obj = JS_THIS_OBJECT(cx, vp); if (!obj) return false; if (!IsLibrary(obj)) { JS_ReportError(cx, "not a library"); return false; } if (args.length() != 0) { JS_ReportError(cx, "close doesn't take any arguments"); return false; } // delete our internal objects UnloadLibrary(obj); JS_SetReservedSlot(obj, SLOT_LIBRARY, PrivateValue(nullptr)); args.rval().setUndefined(); return true; }
JSObject* Library::Create(JSContext* cx, HandleValue path, const JSCTypesCallbacks* callbacks) { RootedObject libraryObj(cx, JS_NewObject(cx, &sLibraryClass)); if (!libraryObj) return nullptr; // initialize the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(nullptr)); // attach API functions if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions)) return nullptr; if (!path.isString()) { JS_ReportErrorASCII(cx, "open takes a string argument"); return nullptr; } PRLibSpec libSpec; RootedFlatString pathStr(cx, JS_FlattenString(cx, path.toString())); if (!pathStr) return nullptr; AutoStableStringChars pathStrChars(cx); if (!pathStrChars.initTwoByte(cx, pathStr)) return nullptr; #ifdef XP_WIN // On Windows, converting to native charset may corrupt path string. // So, we have to use Unicode path directly. char16ptr_t pathChars = pathStrChars.twoByteChars(); libSpec.value.pathname_u = pathChars; libSpec.type = PR_LibSpec_PathnameU; #else // Convert to platform native charset if the appropriate callback has been // provided. char* pathBytes; if (callbacks && callbacks->unicodeToNative) { pathBytes = callbacks->unicodeToNative(cx, pathStrChars.twoByteChars(), pathStr->length()); if (!pathBytes) return nullptr; } else { // Fallback: assume the platform native charset is UTF-8. This is true // for Mac OS X, Android, and probably Linux. size_t nbytes = GetDeflatedUTF8StringLength(cx, pathStrChars.twoByteChars(), pathStr->length()); if (nbytes == (size_t) -1) return nullptr; pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1)); if (!pathBytes) return nullptr; ASSERT_OK(DeflateStringToUTF8Buffer(cx, pathStrChars.twoByteChars(), pathStr->length(), pathBytes, &nbytes)); pathBytes[nbytes] = 0; } libSpec.value.pathname = pathBytes; libSpec.type = PR_LibSpec_Pathname; #endif PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW); #ifndef XP_WIN JS_free(cx, pathBytes); #endif if (!library) { #define MAX_ERROR_LEN 1024 char error[MAX_ERROR_LEN] = "Cannot get error from NSPR."; uint32_t errorLen = PR_GetErrorTextLength(); if (errorLen && errorLen < MAX_ERROR_LEN) PR_GetErrorText(error); #undef MAX_ERROR_LEN if (JS::StringIsASCII(error)) { JSAutoByteString pathCharsUTF8; if (pathCharsUTF8.encodeUtf8(cx, pathStr)) JS_ReportErrorUTF8(cx, "couldn't open library %s: %s", pathCharsUTF8.ptr(), error); } else { JSAutoByteString pathCharsLatin1; if (pathCharsLatin1.encodeLatin1(cx, pathStr)) JS_ReportErrorLatin1(cx, "couldn't open library %s: %s", pathCharsLatin1.ptr(), error); } return nullptr; } // stash the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(library)); return libraryObj; }
void SavedFrame::updatePrivateParent() { setReservedSlot(JSSLOT_PRIVATE_PARENT, PrivateValue(getParent())); }