Bug 959787 - Handlify JS_DefineProperty; r=Waldo, r=bz

--HG--
extra : rebase_source : 87991ed47ed071550af4e4125eea54a66fdb0071
This commit is contained in:
Terrence Cole 2014-01-21 18:11:17 -08:00
Родитель b3c8e42deb
Коммит 581c606391
43 изменённых файлов: 323 добавлений и 325 удалений

Просмотреть файл

@ -958,19 +958,17 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
static_cast<const jschar*>(aMessage.BeginReading()), static_cast<const jschar*>(aMessage.BeginReading()),
aMessage.Length())); aMessage.Length()));
NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY);
JS_DefineProperty(cx, param, "target", targetv, nullptr, nullptr, JSPROP_ENUMERATE); JS::Rooted<JS::Value> syncv(cx, JS::BooleanValue(aIsSync));
JS_DefineProperty(cx, param, "name", JS_DefineProperty(cx, param, "target", targetv, JSPROP_ENUMERATE);
STRING_TO_JSVAL(jsMessage), nullptr, nullptr, JSPROP_ENUMERATE); JS_DefineProperty(cx, param, "name", jsMessage, JSPROP_ENUMERATE);
JS_DefineProperty(cx, param, "sync", JS_DefineProperty(cx, param, "sync", syncv, JSPROP_ENUMERATE);
BOOLEAN_TO_JSVAL(aIsSync), nullptr, nullptr, JSPROP_ENUMERATE); JS_DefineProperty(cx, param, "json", json, JSPROP_ENUMERATE); // deprecated
JS_DefineProperty(cx, param, "json", json, nullptr, nullptr, JSPROP_ENUMERATE); // deprecated JS_DefineProperty(cx, param, "data", json, JSPROP_ENUMERATE);
JS_DefineProperty(cx, param, "data", json, nullptr, nullptr, JSPROP_ENUMERATE); JS_DefineProperty(cx, param, "objects", cpowsv, JSPROP_ENUMERATE);
JS_DefineProperty(cx, param, "objects", cpowsv, nullptr, nullptr, JSPROP_ENUMERATE);
// message.principal == null // message.principal == null
if (!aPrincipal) { if (!aPrincipal) {
JS::Rooted<JS::Value> nullValue(cx); JS_DefineProperty(cx, param, "principal", JS::UndefinedHandleValue, JSPROP_ENUMERATE);
JS_DefineProperty(cx, param, "principal", nullValue, nullptr, nullptr, JSPROP_ENUMERATE);
} }
// message.principal = { appId: <id>, origin: <origin>, isInBrowserElement: <something> } // message.principal = { appId: <id>, origin: <origin>, isInBrowserElement: <something> }
@ -982,25 +980,24 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
nsresult rv = aPrincipal->GetAppId(&appId); nsresult rv = aPrincipal->GetAppId(&appId);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> appIdValue(cx, INT_TO_JSVAL(appId)); JS_DefineProperty(cx, principalObj, "appId", appId, JSPROP_ENUMERATE);
JS_DefineProperty(cx, principalObj, "appId", appIdValue, nullptr, nullptr, JSPROP_ENUMERATE);
nsCString origin; nsCString origin;
rv = aPrincipal->GetOrigin(getter_Copies(origin)); rv = aPrincipal->GetOrigin(getter_Copies(origin));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JSString*> originValue(cx, JS_NewStringCopyN(cx, origin.get(), origin.Length())); JS::Rooted<JSString*> originStr(cx, JS_NewStringCopyN(cx, origin.get(), origin.Length()));
JS_DefineProperty(cx, principalObj, "origin", STRING_TO_JSVAL(originValue), nullptr, nullptr, JSPROP_ENUMERATE); NS_ENSURE_TRUE(originStr, NS_ERROR_OUT_OF_MEMORY);
JS_DefineProperty(cx, principalObj, "origin", originStr, JSPROP_ENUMERATE);
bool browser; bool browser;
rv = aPrincipal->GetIsInBrowserElement(&browser); rv = aPrincipal->GetIsInBrowserElement(&browser);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> browserValue(cx, BOOLEAN_TO_JSVAL(browser)); JS::Rooted<JS::Value> browserValue(cx, JS::BooleanValue(browser));
JS_DefineProperty(cx, principalObj, "isInBrowserElement", browserValue, nullptr, nullptr, JSPROP_ENUMERATE); JS_DefineProperty(cx, principalObj, "isInBrowserElement", browserValue, JSPROP_ENUMERATE);
JS::Rooted<JS::Value> principalValue(cx, JS::ObjectValue(*principalObj)); JS_DefineProperty(cx, param, "principal", principalObj, JSPROP_ENUMERATE);
JS_DefineProperty(cx, param, "principal", principalValue, nullptr, nullptr, JSPROP_ENUMERATE);
} }
JS::Rooted<JS::Value> thisValue(cx, JS::UndefinedValue()); JS::Rooted<JS::Value> thisValue(cx, JS::UndefinedValue());

Просмотреть файл

@ -1651,15 +1651,13 @@ HTMLMediaElement::BuildObjectFromTags(nsCStringHashKey::KeyType aKey,
MetadataIterCx* args = static_cast<MetadataIterCx*>(aUserArg); MetadataIterCx* args = static_cast<MetadataIterCx*>(aUserArg);
nsString wideValue = NS_ConvertUTF8toUTF16(aValue); nsString wideValue = NS_ConvertUTF8toUTF16(aValue);
JSString* string = JS_NewUCStringCopyZ(args->cx, wideValue.Data()); JS::Rooted<JSString*> string(args->cx, JS_NewUCStringCopyZ(args->cx, wideValue.Data()));
if (!string) { if (!string) {
NS_WARNING("Failed to perform string copy"); NS_WARNING("Failed to perform string copy");
args->error = true; args->error = true;
return PL_DHASH_STOP; return PL_DHASH_STOP;
} }
JS::Value value = STRING_TO_JSVAL(string); if (!JS_DefineProperty(args->cx, args->tags, aKey.Data(), string, JSPROP_ENUMERATE)) {
if (!JS_DefineProperty(args->cx, args->tags, aKey.Data(), value,
nullptr, nullptr, JSPROP_ENUMERATE)) {
NS_WARNING("Failed to set metadata property"); NS_WARNING("Failed to set metadata property");
args->error = true; args->error = true;
return PL_DHASH_STOP; return PL_DHASH_STOP;

Просмотреть файл

@ -695,8 +695,7 @@ Console::ProfileMethod(JSContext* aCx, const nsAString& aAction,
JS::Rooted<JSObject*> eventObj(aCx, &eventValue.toObject()); JS::Rooted<JSObject*> eventObj(aCx, &eventValue.toObject());
MOZ_ASSERT(eventObj); MOZ_ASSERT(eventObj);
if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue, if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return; return;
} }
@ -1004,8 +1003,7 @@ Console::ProcessCallData(ConsoleCallData* aData)
JS::Rooted<JSObject*> eventObj(cx, &eventValue.toObject()); JS::Rooted<JSObject*> eventObj(cx, &eventValue.toObject());
MOZ_ASSERT(eventObj); MOZ_ASSERT(eventObj);
if (!JS_DefineProperty(cx, eventObj, "wrappedJSObject", eventValue, if (!JS_DefineProperty(cx, eventObj, "wrappedJSObject", eventValue, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
return; return;
} }

Просмотреть файл

@ -2047,6 +2047,7 @@ DefineInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *
uint16_t parent_constant_count, i; uint16_t parent_constant_count, i;
parent_if_info->GetConstantCount(&parent_constant_count); parent_if_info->GetConstantCount(&parent_constant_count);
JS::Rooted<JS::Value> v(cx);
for (i = parent_constant_count; i < constant_count; i++) { for (i = parent_constant_count; i < constant_count; i++) {
const nsXPTConstant *c = nullptr; const nsXPTConstant *c = nullptr;
@ -2055,18 +2056,18 @@ DefineInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *
uint16_t type = c->GetType().TagPart(); uint16_t type = c->GetType().TagPart();
jsval v; v.setUndefined();
switch (type) { switch (type) {
case nsXPTType::T_I8: case nsXPTType::T_I8:
case nsXPTType::T_U8: case nsXPTType::T_U8:
{ {
v = INT_TO_JSVAL(c->GetValue()->val.u8); v.setInt32(c->GetValue()->val.u8);
break; break;
} }
case nsXPTType::T_I16: case nsXPTType::T_I16:
case nsXPTType::T_U16: case nsXPTType::T_U16:
{ {
v = INT_TO_JSVAL(c->GetValue()->val.u16); v.setInt32(c->GetValue()->val.u16);
break; break;
} }
case nsXPTType::T_I32: case nsXPTType::T_I32:
@ -2089,9 +2090,9 @@ DefineInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *
} }
if (!::JS_DefineProperty(cx, obj, c->GetName(), v, if (!::JS_DefineProperty(cx, obj, c->GetName(), v,
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_ENUMERATE | JSPROP_READONLY |
JSPROP_PERMANENT)) { JSPROP_PERMANENT,
JS_PropertyStub, JS_StrictPropertyStub)) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
} }
@ -2703,8 +2704,8 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
// Per ECMA, the prototype property is {DontEnum, DontDelete, ReadOnly} // Per ECMA, the prototype property is {DontEnum, DontDelete, ReadOnly}
if (!JS_WrapValue(cx, &v) || if (!JS_WrapValue(cx, &v) ||
!JS_DefineProperty(cx, class_obj, "prototype", v, !JS_DefineProperty(cx, class_obj, "prototype", v,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT | JSPROP_READONLY,
JSPROP_PERMANENT | JSPROP_READONLY)) { JS_PropertyStub, JS_StrictPropertyStub)) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
@ -3204,9 +3205,9 @@ LookupComponentsShim(JSContext *cx, JS::Handle<JSObject*> global,
JS::Rooted<JSObject*> interfaces(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), global)); JS::Rooted<JSObject*> interfaces(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), global));
NS_ENSURE_TRUE(interfaces, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(interfaces, NS_ERROR_OUT_OF_MEMORY);
bool ok = bool ok =
JS_DefineProperty(cx, components, "interfaces", JS::ObjectValue(*interfaces), JS_DefineProperty(cx, components, "interfaces", interfaces,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_PropertyStub, JS_StrictPropertyStub);
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
// Define a bunch of shims from the Ci.nsIDOMFoo to window.Foo for DOM // Define a bunch of shims from the Ci.nsIDOMFoo to window.Foo for DOM
@ -3228,8 +3229,8 @@ LookupComponentsShim(JSContext *cx, JS::Handle<JSObject*> global,
// Define the shim on the interfaces object. // Define the shim on the interfaces object.
ok = JS_DefineProperty(cx, interfaces, geckoName, v, ok = JS_DefineProperty(cx, interfaces, geckoName, v,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_PropertyStub, JS_StrictPropertyStub);
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
} }
@ -3390,8 +3391,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
if (xpc::WrapperFactory::IsXrayWrapper(obj)) { if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
*_retval = JS_WrapValue(cx, &v) && *_retval = JS_WrapValue(cx, &v) &&
JS_DefineProperty(cx, obj, "document", v, JS_DefineProperty(cx, obj, "document", v,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_READONLY | JSPROP_ENUMERATE,
JSPROP_READONLY | JSPROP_ENUMERATE); JS_PropertyStub, JS_StrictPropertyStub);
if (!*_retval) { if (!*_retval) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }

Просмотреть файл

@ -2543,10 +2543,10 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
} }
if (!aState) { if (!aState) {
if (!JS_DefineProperty(cx, newInnerGlobal, "window", JS::Rooted<JSObject*> rootedWrapper(cx, GetWrapperPreserveColor());
OBJECT_TO_JSVAL(GetWrapperPreserveColor()), if (!JS_DefineProperty(cx, newInnerGlobal, "window", rootedWrapper,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT,
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) { JS_PropertyStub, JS_StrictPropertyStub)) {
NS_ERROR("can't create the 'window' property"); NS_ERROR("can't create the 'window' property");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -4460,9 +4460,8 @@ nsGlobalWindow::SetOpener(nsIDOMWindow* aOpener, ErrorResult& aError)
if (!JS_WrapObject(cx, &otherObj) || if (!JS_WrapObject(cx, &otherObj) ||
!JS_WrapObject(cx, &thisObj) || !JS_WrapObject(cx, &thisObj) ||
!JS_DefineProperty(cx, thisObj, "opener", JS::ObjectValue(*otherObj), !JS_DefineProperty(cx, thisObj, "opener", otherObj, JSPROP_ENUMERATE,
JS_PropertyStub, JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub)) {
JSPROP_ENUMERATE)) {
aError.Throw(NS_ERROR_FAILURE); aError.Throw(NS_ERROR_FAILURE);
} }
@ -13601,8 +13600,8 @@ nsGlobalWindow::SetConsole(JSContext* aCx, JS::Handle<JS::Value> aValue)
if (!JS_WrapObject(aCx, &thisObj) || if (!JS_WrapObject(aCx, &thisObj) ||
!JS_DefineProperty(aCx, thisObj, "console", aValue, !JS_DefineProperty(aCx, thisObj, "console", aValue,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE, JS_PropertyStub,
JSPROP_ENUMERATE)) { JS_StrictPropertyStub)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

Просмотреть файл

@ -1001,14 +1001,12 @@ nsJSContext::SetProperty(JS::Handle<JSObject*> aTarget, const char* aPropName, n
} }
} }
JSObject* array = ::JS_NewArrayObject(mContext, args); JS::Rooted<JSObject*> array(mContext, ::JS_NewArrayObject(mContext, args));
if (!array) { if (!array) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
JS::Rooted<JS::Value> arrayVal(mContext, JS::ObjectValue(*array));
return JS_DefineProperty(mContext, aTarget, aPropName, arrayVal, return JS_DefineProperty(mContext, aTarget, aPropName, array, 0) ? NS_OK : NS_ERROR_FAILURE;
nullptr, nullptr, 0) ? NS_OK : NS_ERROR_FAILURE;
} }
nsresult nsresult

Просмотреть файл

@ -272,9 +272,11 @@ bool
DefineConstants(JSContext* cx, JS::Handle<JSObject*> obj, DefineConstants(JSContext* cx, JS::Handle<JSObject*> obj,
const ConstantSpec* cs) const ConstantSpec* cs)
{ {
JS::Rooted<JS::Value> value(cx);
for (; cs->name; ++cs) { for (; cs->name; ++cs) {
value = cs->value;
bool ok = bool ok =
JS_DefineProperty(cx, obj, cs->name, cs->value, nullptr, nullptr, JS_DefineProperty(cx, obj, cs->name, value,
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
if (!ok) { if (!ok) {
return false; return false;
@ -415,8 +417,7 @@ DefineConstructor(JSContext* cx, JS::Handle<JSObject*> global, const char* name,
// This is Enumerable: False per spec. // This is Enumerable: False per spec.
return alreadyDefined || return alreadyDefined ||
JS_DefineProperty(cx, global, name, OBJECT_TO_JSVAL(constructor), JS_DefineProperty(cx, global, name, constructor, 0);
nullptr, nullptr, 0);
} }
static JSObject* static JSObject*
@ -467,8 +468,8 @@ CreateInterfaceObject(JSContext* cx, JS::Handle<JSObject*> global,
js::SetFunctionNativeReserved(toStringObj, TOSTRING_NAME_RESERVED_SLOT, js::SetFunctionNativeReserved(toStringObj, TOSTRING_NAME_RESERVED_SLOT,
STRING_TO_JSVAL(str)); STRING_TO_JSVAL(str));
if (!JS_DefineProperty(cx, constructor, "length", JS::Int32Value(ctorNargs), if (!JS_DefineProperty(cx, constructor, "length", ctorNargs,
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT)) { JSPROP_READONLY | JSPROP_PERMANENT)) {
return nullptr; return nullptr;
} }
} }
@ -525,9 +526,8 @@ CreateInterfaceObject(JSContext* cx, JS::Handle<JSObject*> global,
namedConstructors->mNargs)); namedConstructors->mNargs));
if (!namedConstructor || if (!namedConstructor ||
!JS_DefineProperty(cx, namedConstructor, "prototype", !JS_DefineProperty(cx, namedConstructor, "prototype",
JS::ObjectValue(*proto), JS_PropertyStub, proto, JSPROP_PERMANENT | JSPROP_READONLY,
JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub) ||
JSPROP_PERMANENT | JSPROP_READONLY) ||
(defineOnGlobal && (defineOnGlobal &&
!DefineConstructor(cx, global, namedConstructors->mName, !DefineConstructor(cx, global, namedConstructors->mName,
namedConstructor))) { namedConstructor))) {

Просмотреть файл

@ -6482,7 +6482,7 @@ class CGJsonifierMethod(CGSpecializedMethod):
' if (!get_%s(cx, obj, self, JSJitGetterCallArgs(&temp))) {\n' ' if (!get_%s(cx, obj, self, JSJitGetterCallArgs(&temp))) {\n'
' return false;\n' ' return false;\n'
' }\n' ' }\n'
' if (!JS_DefineProperty(cx, result, "%s", temp, nullptr, nullptr, JSPROP_ENUMERATE)) {\n' ' if (!JS_DefineProperty(cx, result, "%s", temp, JSPROP_ENUMERATE)) {\n'
' return false;\n' ' return false;\n'
' }\n' ' }\n'
'}\n' % (m.identifier.name, m.identifier.name)) '}\n' % (m.identifier.name, m.identifier.name))
@ -6900,7 +6900,7 @@ class CGSpecializedReplaceableSetter(CGSpecializedSetter):
attrName = self.attr.identifier.name attrName = self.attr.identifier.name
# JS_DefineProperty can only deal with ASCII # JS_DefineProperty can only deal with ASCII
assert all(ord(c) < 128 for c in attrName) assert all(ord(c) < 128 for c in attrName)
return CGIndenter(CGGeneric("""return JS_DefineProperty(cx, obj, "%s", args[0], nullptr, nullptr, JSPROP_ENUMERATE);""" % attrName)).define() return CGIndenter(CGGeneric("""return JS_DefineProperty(cx, obj, "%s", args[0], JSPROP_ENUMERATE);""" % attrName)).define()
def memberReturnsNewObject(member): def memberReturnsNewObject(member):
@ -11660,7 +11660,7 @@ class CGJSImplClass(CGBindingImplClass):
"if (!JS_WrapObject(aCx, &obj)) {\n" "if (!JS_WrapObject(aCx, &obj)) {\n"
" return nullptr;\n" " return nullptr;\n"
"}\n" "}\n"
'if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", JS::ObjectValue(*obj), nullptr, nullptr, 0)) {\n' 'if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", obj, 0)) {\n'
" return nullptr;\n" " return nullptr;\n"
"}\n" "}\n"
"return obj;" % self.descriptor.name) "return obj;" % self.descriptor.name)

Просмотреть файл

@ -33,10 +33,9 @@ MetadataHelper::GetSuccessResult(JSContext* aCx,
NS_ENSURE_TRUE(obj, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(obj, NS_ERROR_OUT_OF_MEMORY);
if (mParams->SizeRequested()) { if (mParams->SizeRequested()) {
JS::Value val = JS_NumberValue(mParams->Size()); JS::Rooted<JS::Value> val(aCx, JS_NumberValue(mParams->Size()));
if (!JS_DefineProperty(aCx, obj, "size", val, nullptr, nullptr, if (!JS_DefineProperty(aCx, obj, "size", val, JSPROP_ENUMERATE)) {
JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }
@ -46,8 +45,9 @@ MetadataHelper::GetSuccessResult(JSContext* aCx,
JSObject *date = JS_NewDateObjectMsec(aCx, msec); JSObject *date = JS_NewDateObjectMsec(aCx, msec);
NS_ENSURE_TRUE(date, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(date, NS_ERROR_OUT_OF_MEMORY);
if (!JS_DefineProperty(aCx, obj, "lastModified", OBJECT_TO_JSVAL(date), JS::Rooted<JS::Value> dateRoot(aCx, JS::ObjectValue(*date));
nullptr, nullptr, JSPROP_ENUMERATE)) { if (!JS_DefineProperty(aCx, obj, "lastModified", dateRoot,
JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }

Просмотреть файл

@ -907,11 +907,8 @@ public:
JS::Rooted<JSString*> type(aCx, JS::Rooted<JSString*> type(aCx,
JS_NewUCStringCopyN(aCx, aData.type.get(), aData.type.Length())); JS_NewUCStringCopyN(aCx, aData.type.get(), aData.type.Length()));
if (!type || if (!type ||
!JS_DefineProperty(aCx, obj, "size", !JS_DefineProperty(aCx, obj, "size", double(aData.size), 0) ||
JS_NumberValue((double)aData.size), !JS_DefineProperty(aCx, obj, "type", type, 0)) {
nullptr, nullptr, 0) ||
!JS_DefineProperty(aCx, obj, "type", STRING_TO_JSVAL(type),
nullptr, nullptr, 0)) {
return nullptr; return nullptr;
} }
@ -924,10 +921,8 @@ public:
JS::Rooted<JSObject*> date(aCx, JS::Rooted<JSObject*> date(aCx,
JS_NewDateObjectMsec(aCx, aData.lastModifiedDate)); JS_NewDateObjectMsec(aCx, aData.lastModifiedDate));
if (!name || !date || if (!name || !date ||
!JS_DefineProperty(aCx, obj, "name", STRING_TO_JSVAL(name), !JS_DefineProperty(aCx, obj, "name", name, 0) ||
nullptr, nullptr, 0) || !JS_DefineProperty(aCx, obj, "lastModifiedDate", date, 0)) {
!JS_DefineProperty(aCx, obj, "lastModifiedDate", OBJECT_TO_JSVAL(date),
nullptr, nullptr, 0)) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -446,8 +446,7 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
return false; return false;
} }
return JS_DefineProperty(aCx, aGlobal, IDB_STR, indexedDB, nullptr, nullptr, return JS_DefineProperty(aCx, aGlobal, IDB_STR, indexedDB, JSPROP_ENUMERATE);
JSPROP_ENUMERATE);
} }
// static // static

Просмотреть файл

@ -544,8 +544,7 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachm
aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr())); aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
NS_ENSURE_TRUE(attachmentObj, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(attachmentObj, NS_ERROR_OUT_OF_MEMORY);
JS::Rooted<JS::Value> tmpJsVal(aCx); JS::Rooted<JSString*> tmpJsStr(aCx);
JSString* tmpJsStr;
// Get |attachment.mId|. // Get |attachment.mId|.
tmpJsStr = JS_NewUCStringCopyN(aCx, tmpJsStr = JS_NewUCStringCopyN(aCx,
@ -553,9 +552,7 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachm
attachment.id.Length()); attachment.id.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr); if (!JS_DefineProperty(aCx, attachmentObj, "id", tmpJsStr, JSPROP_ENUMERATE)) {
if (!JS_DefineProperty(aCx, attachmentObj, "id", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -565,21 +562,19 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachm
attachment.location.Length()); attachment.location.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr); if (!JS_DefineProperty(aCx, attachmentObj, "location", tmpJsStr, JSPROP_ENUMERATE)) {
if (!JS_DefineProperty(aCx, attachmentObj, "location", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// Get |attachment.mContent|. // Get |attachment.mContent|.
JS::Rooted<JS::Value> tmpJsVal(aCx);
nsresult rv = nsContentUtils::WrapNative(aCx, nsresult rv = nsContentUtils::WrapNative(aCx,
attachment.content, attachment.content,
&NS_GET_IID(nsIDOMBlob), &NS_GET_IID(nsIDOMBlob),
&tmpJsVal); &tmpJsVal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal, if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

Просмотреть файл

@ -39,21 +39,19 @@ MmsAttachmentDataToJSObject(JSContext* aContext,
JS::NullPtr())); JS::NullPtr()));
NS_ENSURE_TRUE(obj, nullptr); NS_ENSURE_TRUE(obj, nullptr);
JSString* idStr = JS_NewUCStringCopyN(aContext, JS::Rooted<JSString*> idStr(aContext, JS_NewUCStringCopyN(aContext,
aAttachment.id().get(), aAttachment.id().get(),
aAttachment.id().Length()); aAttachment.id().Length()));
NS_ENSURE_TRUE(idStr, nullptr); NS_ENSURE_TRUE(idStr, nullptr);
if (!JS_DefineProperty(aContext, obj, "id", JS::StringValue(idStr), if (!JS_DefineProperty(aContext, obj, "id", idStr, 0)) {
nullptr, nullptr, 0)) {
return nullptr; return nullptr;
} }
JSString* locStr = JS_NewUCStringCopyN(aContext, JS::Rooted<JSString*> locStr(aContext, JS_NewUCStringCopyN(aContext,
aAttachment.location().get(), aAttachment.location().get(),
aAttachment.location().Length()); aAttachment.location().Length()));
NS_ENSURE_TRUE(locStr, nullptr); NS_ENSURE_TRUE(locStr, nullptr);
if (!JS_DefineProperty(aContext, obj, "location", JS::StringValue(locStr), if (!JS_DefineProperty(aContext, obj, "location", locStr, 0)) {
nullptr, nullptr, 0)) {
return nullptr; return nullptr;
} }
@ -64,8 +62,7 @@ MmsAttachmentDataToJSObject(JSContext* aContext,
&NS_GET_IID(nsIDOMBlob), &NS_GET_IID(nsIDOMBlob),
&content); &content);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
if (!JS_DefineProperty(aContext, obj, "content", content, if (!JS_DefineProperty(aContext, obj, "content", content, 0)) {
nullptr, nullptr, 0)) {
return nullptr; return nullptr;
} }
@ -81,22 +78,20 @@ GetParamsFromSendMmsMessageRequest(JSContext* aCx,
NS_ENSURE_TRUE(paramsObj, false); NS_ENSURE_TRUE(paramsObj, false);
// smil // smil
JSString* smilStr = JS_NewUCStringCopyN(aCx, JS::Rooted<JSString*> smilStr(aCx, JS_NewUCStringCopyN(aCx,
aRequest.smil().get(), aRequest.smil().get(),
aRequest.smil().Length()); aRequest.smil().Length()));
NS_ENSURE_TRUE(smilStr, false); NS_ENSURE_TRUE(smilStr, false);
if(!JS_DefineProperty(aCx, paramsObj, "smil", JS::StringValue(smilStr), if(!JS_DefineProperty(aCx, paramsObj, "smil", smilStr, 0)) {
nullptr, nullptr, 0)) {
return false; return false;
} }
// subject // subject
JSString* subjectStr = JS_NewUCStringCopyN(aCx, JS::Rooted<JSString*> subjectStr(aCx, JS_NewUCStringCopyN(aCx,
aRequest.subject().get(), aRequest.subject().get(),
aRequest.subject().Length()); aRequest.subject().Length()));
NS_ENSURE_TRUE(subjectStr, false); NS_ENSURE_TRUE(subjectStr, false);
if(!JS_DefineProperty(aCx, paramsObj, "subject", if(!JS_DefineProperty(aCx, paramsObj, "subject", subjectStr, 0)) {
JS::StringValue(subjectStr), nullptr, nullptr, 0)) {
return false; return false;
} }
@ -107,8 +102,7 @@ GetParamsFromSendMmsMessageRequest(JSContext* aCx,
receiverArray.address()))) { receiverArray.address()))) {
return false; return false;
} }
if (!JS_DefineProperty(aCx, paramsObj, "receivers", if (!JS_DefineProperty(aCx, paramsObj, "receivers", receiverArray, 0)) {
JS::ObjectValue(*receiverArray), nullptr, nullptr, 0)) {
return false; return false;
} }
@ -124,8 +118,7 @@ GetParamsFromSendMmsMessageRequest(JSContext* aCx,
} }
} }
if (!JS_DefineProperty(aCx, paramsObj, "attachments", if (!JS_DefineProperty(aCx, paramsObj, "attachments", attachmentArray, 0)) {
JS::ObjectValue(*attachmentArray), nullptr, nullptr, 0)) {
return false; return false;
} }

Просмотреть файл

@ -897,10 +897,9 @@ GetOrCreateClassObjectMap(JSContext *cx, JS::Handle<JSObject*> scope, const char
// It's not there. Create and define it. // It's not there. Create and define it.
JS::Rooted<JSObject*> map(cx, JS::NewWeakMapObject(cx)); JS::Rooted<JSObject*> map(cx, JS::NewWeakMapObject(cx));
if (!map || !JS_DefineProperty(cx, scope, mapName, if (!map || !JS_DefineProperty(cx, scope, mapName, map,
JS::ObjectValue(*map), JSPROP_PERMANENT | JSPROP_READONLY,
JS_PropertyStub, JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub))
JSPROP_PERMANENT | JSPROP_READONLY))
{ {
return nullptr; return nullptr;
} }
@ -1042,9 +1041,9 @@ nsXBLBinding::DoInitJSClass(JSContext *cx,
// stick it on. // stick it on.
JSAutoCompartment ac3(cx, holder); JSAutoCompartment ac3(cx, holder);
if (!JS_WrapObject(cx, &proto) || if (!JS_WrapObject(cx, &proto) ||
!JS_DefineProperty(cx, holder, aClassName.get(), JS::ObjectValue(*proto), !JS_DefineProperty(cx, holder, aClassName.get(), proto,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_READONLY | JSPROP_PERMANENT,
JSPROP_READONLY | JSPROP_PERMANENT)) JS_PropertyStub, JS_StrictPropertyStub))
{ {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }

Просмотреть файл

@ -92,9 +92,8 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
// Define it as a property on the scopeObject, using the same name used on // Define it as a property on the scopeObject, using the same name used on
// the content side. // the content side.
bool ok = JS_DefineProperty(cx, scopeObject, aPrototypeBinding->ClassName().get(), bool ok = JS_DefineProperty(cx, scopeObject, aPrototypeBinding->ClassName().get(),
JS::ObjectValue(*propertyHolder), JS_PropertyStub, propertyHolder, JSPROP_PERMANENT | JSPROP_READONLY,
JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub);
JSPROP_PERMANENT | JSPROP_READONLY);
NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
} else { } else {
propertyHolder = targetClassObject; propertyHolder = targetClassObject;

Просмотреть файл

@ -546,10 +546,10 @@ XPCShellEnvironment::Init()
backstagePass->SetGlobalObject(globalObj); backstagePass->SetGlobalObject(globalObj);
JS::Rooted<Value> privateVal(cx, PrivateValue(this));
if (!JS_DefineProperty(cx, globalObj, "__XPCShellEnvironment", if (!JS_DefineProperty(cx, globalObj, "__XPCShellEnvironment",
PRIVATE_TO_JSVAL(this), JS_PropertyStub, privateVal, JSPROP_READONLY | JSPROP_PERMANENT,
JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub) ||
JSPROP_READONLY | JSPROP_PERMANENT) ||
!JS_DefineFunctions(cx, globalObj, gGlobalFunctions) || !JS_DefineFunctions(cx, globalObj, gGlobalFunctions) ||
!JS_DefineProfilingFunctions(cx, globalObj)) !JS_DefineProfilingFunctions(cx, globalObj))
{ {

Просмотреть файл

@ -1073,7 +1073,7 @@ MapObject::initClass(JSContext *cx, JSObject *obj)
// Define its alias. // Define its alias.
RootedValue funval(cx, ObjectValue(*fun)); RootedValue funval(cx, ObjectValue(*fun));
if (!JS_DefineProperty(cx, proto, js_std_iterator_str, funval, nullptr, nullptr, 0)) if (!JS_DefineProperty(cx, proto, js_std_iterator_str, funval, 0))
return nullptr; return nullptr;
} }
return proto; return proto;
@ -1642,9 +1642,9 @@ SetObject::initClass(JSContext *cx, JSObject *obj)
// Define its aliases. // Define its aliases.
RootedValue funval(cx, ObjectValue(*fun)); RootedValue funval(cx, ObjectValue(*fun));
if (!JS_DefineProperty(cx, proto, "keys", funval, nullptr, nullptr, 0)) if (!JS_DefineProperty(cx, proto, "keys", funval, 0))
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, proto, js_std_iterator_str, funval, nullptr, nullptr, 0)) if (!JS_DefineProperty(cx, proto, js_std_iterator_str, funval, 0))
return nullptr; return nullptr;
} }
return proto; return proto;

Просмотреть файл

@ -1055,14 +1055,14 @@ ShellObjectMetadataCallback(JSContext *cx, JSObject **pmetadata)
static int createdIndex = 0; static int createdIndex = 0;
createdIndex++; createdIndex++;
if (!JS_DefineProperty(cx, obj, "index", Int32Value(createdIndex), if (!JS_DefineProperty(cx, obj, "index", createdIndex, 0,
JS_PropertyStub, JS_StrictPropertyStub, 0)) JS_PropertyStub, JS_StrictPropertyStub))
{ {
return false; return false;
} }
if (!JS_DefineProperty(cx, obj, "stack", ObjectValue(*stack), if (!JS_DefineProperty(cx, obj, "stack", stack, 0,
JS_PropertyStub, JS_StrictPropertyStub, 0)) JS_PropertyStub, JS_StrictPropertyStub))
{ {
return false; return false;
} }

Просмотреть файл

@ -879,12 +879,12 @@ InitCTypeClass(JSContext* cx, HandleObject parent)
if (!prototype) if (!prototype)
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, ctor, "prototype", OBJECT_TO_JSVAL(prototype), if (!JS_DefineProperty(cx, ctor, "prototype", prototype,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(ctor), if (!JS_DefineProperty(cx, prototype, "constructor", ctor,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return nullptr; return nullptr;
// Define properties and functions common to all CTypes. // Define properties and functions common to all CTypes.
@ -935,12 +935,12 @@ InitCDataClass(JSContext* cx, HandleObject parent, HandleObject CTypeProto)
if (!prototype) if (!prototype)
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, ctor, "prototype", OBJECT_TO_JSVAL(prototype), if (!JS_DefineProperty(cx, ctor, "prototype", prototype,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(ctor), if (!JS_DefineProperty(cx, prototype, "constructor", ctor,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return nullptr; return nullptr;
// Define properties and functions common to all CDatas. // Define properties and functions common to all CDatas.
@ -1000,8 +1000,8 @@ InitTypeConstructor(JSContext* cx,
return false; return false;
// Define property before proceeding, for GC safety. // Define property before proceeding, for GC safety.
if (!JS_DefineProperty(cx, obj, "prototype", OBJECT_TO_JSVAL(typeProto), if (!JS_DefineProperty(cx, obj, "prototype", typeProto,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
if (fns && !JS_DefineFunctions(cx, typeProto, fns)) if (fns && !JS_DefineFunctions(cx, typeProto, fns))
@ -1010,8 +1010,8 @@ InitTypeConstructor(JSContext* cx,
if (!JS_DefineProperties(cx, typeProto, props)) if (!JS_DefineProperties(cx, typeProto, props))
return false; return false;
if (!JS_DefineProperty(cx, typeProto, "constructor", OBJECT_TO_JSVAL(obj), if (!JS_DefineProperty(cx, typeProto, "constructor", obj,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
// Stash ctypes.{Pointer,Array,Struct}Type.prototype on a reserved slot of // Stash ctypes.{Pointer,Array,Struct}Type.prototype on a reserved slot of
@ -1246,9 +1246,8 @@ InitTypeClasses(JSContext* cx, HandleObject parent)
// Alias 'ctypes.unsigned' as 'ctypes.unsigned_int', since they represent // Alias 'ctypes.unsigned' as 'ctypes.unsigned_int', since they represent
// the same type in C. // the same type in C.
if (!JS_DefineProperty(cx, parent, "unsigned", if (!JS_DefineProperty(cx, parent, "unsigned", typeObj_unsigned_int,
OBJECT_TO_JSVAL(typeObj_unsigned_int), nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
// Create objects representing the special types void_t and voidptr_t. // Create objects representing the special types void_t and voidptr_t.
@ -1261,8 +1260,8 @@ InitTypeClasses(JSContext* cx, HandleObject parent)
typeObj = PointerType::CreateInternal(cx, typeObj); typeObj = PointerType::CreateInternal(cx, typeObj);
if (!typeObj) if (!typeObj)
return false; return false;
if (!JS_DefineProperty(cx, parent, "voidptr_t", OBJECT_TO_JSVAL(typeObj), if (!JS_DefineProperty(cx, parent, "voidptr_t", typeObj,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
return true; return true;
@ -1327,8 +1326,8 @@ JS_InitCTypesClass(JSContext* cx, HandleObject global)
if (!ctypes) if (!ctypes)
return false; return false;
if (!JS_DefineProperty(cx, global, "ctypes", OBJECT_TO_JSVAL(ctypes), if (!JS_DefineProperty(cx, global, "ctypes", ctypes, JSPROP_READONLY | JSPROP_PERMANENT,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_READONLY | JSPROP_PERMANENT)){ JS_PropertyStub, JS_StrictPropertyStub)){
return false; return false;
} }
@ -1352,12 +1351,12 @@ JS_InitCTypesClass(JSContext* cx, HandleObject global)
if (!JS_DefineFunctions(cx, prototype, sCDataFinalizerFunctions)) if (!JS_DefineFunctions(cx, prototype, sCDataFinalizerFunctions))
return false; return false;
if (!JS_DefineProperty(cx, ctor, "prototype", OBJECT_TO_JSVAL(prototype), if (!JS_DefineProperty(cx, ctor, "prototype", prototype,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(ctor), if (!JS_DefineProperty(cx, prototype, "constructor", ctor,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
@ -3232,8 +3231,8 @@ CType::Create(JSContext* cx,
if (!prototype) if (!prototype)
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(typeObj), if (!JS_DefineProperty(cx, prototype, "constructor", typeObj,
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_READONLY | JSPROP_PERMANENT))
return nullptr; return nullptr;
// Set the 'prototype' object. // Set the 'prototype' object.
@ -3281,8 +3280,8 @@ CType::DefineBuiltin(JSContext* cx,
return nullptr; return nullptr;
// Define the CType as a 'propName' property on 'parent'. // Define the CType as a 'propName' property on 'parent'.
if (!JS_DefineProperty(cx, parent, propName, OBJECT_TO_JSVAL(typeObj), if (!JS_DefineProperty(cx, parent, propName, typeObj,
nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
return nullptr; return nullptr;
return typeObj; return typeObj;
@ -4794,8 +4793,8 @@ StructType::DefineInternal(JSContext* cx, JSObject* typeObj_, JSObject* fieldsOb
if (!prototype) if (!prototype)
return false; return false;
if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(typeObj), if (!JS_DefineProperty(cx, prototype, "constructor", typeObj,
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT)) JSPROP_READONLY | JSPROP_PERMANENT))
return false; return false;
// Create a FieldInfoHash to stash on the type object, and an array to root // Create a FieldInfoHash to stash on the type object, and an array to root

Просмотреть файл

@ -46,9 +46,8 @@ BEGIN_TEST(testAddPropertyHook)
CHECK(obj); CHECK(obj);
JS::RootedValue arr(cx, OBJECT_TO_JSVAL(obj)); JS::RootedValue arr(cx, OBJECT_TO_JSVAL(obj));
CHECK(JS_DefineProperty(cx, global, "arr", arr, CHECK(JS_DefineProperty(cx, global, "arr", arr, JSPROP_ENUMERATE,
JS_PropertyStub, JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub));
JSPROP_ENUMERATE));
for (int i = 0; i < ExpectedCount; ++i) { for (int i = 0; i < ExpectedCount; ++i) {
obj = JS_NewObject(cx, &AddPropertyClass, JS::NullPtr(), JS::NullPtr()); obj = JS_NewObject(cx, &AddPropertyClass, JS::NullPtr(), JS::NullPtr());

Просмотреть файл

@ -34,16 +34,16 @@ BEGIN_TEST(testDefineGetterSetterNonEnumerable)
JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj)); JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj));
CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME,
JSVAL_VOID, JS::UndefinedHandleValue,
JSPROP_GETTER | JSPROP_SETTER | JSPROP_ENUMERATE,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj),
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj), JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj)));
JSPROP_GETTER | JSPROP_SETTER | JSPROP_ENUMERATE));
CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME,
JSVAL_VOID, JS::UndefinedHandleValue,
JSPROP_GETTER | JSPROP_SETTER | JSPROP_PERMANENT,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj),
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj), JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj)));
JSPROP_GETTER | JSPROP_SETTER | JSPROP_PERMANENT));
JS::Rooted<JSPropertyDescriptor> desc(cx); JS::Rooted<JSPropertyDescriptor> desc(cx);
CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, 0, &desc)); CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, 0, &desc));

Просмотреть файл

@ -17,7 +17,7 @@ BEGIN_TEST(testDefineProperty_bug564344)
JS::RootedObject obj(cx, JSVAL_TO_OBJECT(x)); JS::RootedObject obj(cx, JSVAL_TO_OBJECT(x));
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
CHECK(JS_DefineProperty(cx, obj, "q", JSVAL_VOID, nullptr, nullptr, JSPROP_SHARED)); CHECK(JS_DefineProperty(cx, obj, "q", JS::UndefinedHandleValue, JSPROP_SHARED));
return true; return true;
} }
END_TEST(testDefineProperty_bug564344) END_TEST(testDefineProperty_bug564344)

Просмотреть файл

@ -15,8 +15,8 @@ BEGIN_TEST(testGCExactRooting)
JS_GC(cx->runtime()); JS_GC(cx->runtime());
/* Use the objects we just created to ensure that they are still alive. */ /* Use the objects we just created to ensure that they are still alive. */
JS_DefineProperty(cx, rootCx, "foo", JS::DoubleValue(0), nullptr, nullptr, 0); JS_DefineProperty(cx, rootCx, "foo", JS::UndefinedHandleValue, 0);
JS_DefineProperty(cx, rootRt, "foo", JS::DoubleValue(0), nullptr, nullptr, 0); JS_DefineProperty(cx, rootRt, "foo", JS::UndefinedHandleValue, 0);
return true; return true;
} }

Просмотреть файл

@ -87,7 +87,7 @@ BEGIN_TEST(testLookup_bug570195)
{ {
JS::RootedObject obj(cx, JS_NewObject(cx, &document_class, JS::NullPtr(), JS::NullPtr())); JS::RootedObject obj(cx, JS_NewObject(cx, &document_class, JS::NullPtr(), JS::NullPtr()));
CHECK(obj); CHECK(obj);
CHECK(JS_DefineProperty(cx, global, "document", OBJECT_TO_JSVAL(obj), nullptr, nullptr, 0)); CHECK(JS_DefineProperty(cx, global, "document", obj, 0));
JS::RootedValue v(cx); JS::RootedValue v(cx);
EVAL("document.all ? true : false", &v); EVAL("document.all ? true : false", &v);
CHECK_SAME(v, JSVAL_FALSE); CHECK_SAME(v, JSVAL_FALSE);

Просмотреть файл

@ -38,8 +38,10 @@ BEGIN_TEST(testResolveRecursion)
JS_SetPrivate(obj1, this); JS_SetPrivate(obj1, this);
JS_SetPrivate(obj2, this); JS_SetPrivate(obj2, this);
CHECK(JS_DefineProperty(cx, global, "obj1", OBJECT_TO_JSVAL(obj1), nullptr, nullptr, 0)); JS::RootedValue obj1Val(cx, ObjectValue(*obj1));
CHECK(JS_DefineProperty(cx, global, "obj2", OBJECT_TO_JSVAL(obj2), nullptr, nullptr, 0)); JS::RootedValue obj2Val(cx, ObjectValue(*obj2));
CHECK(JS_DefineProperty(cx, global, "obj1", obj1Val, 0));
CHECK(JS_DefineProperty(cx, global, "obj2", obj2Val, 0));
resolveEntryCount = 0; resolveEntryCount = 0;
resolveExitCount = 0; resolveExitCount = 0;

Просмотреть файл

@ -11,15 +11,12 @@ BEGIN_TEST(testSetProperty_NativeGetterStubSetter)
{ {
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
CHECK(obj); CHECK(obj);
JS::RootedValue vobj(cx, OBJECT_TO_JSVAL(obj));
CHECK(JS_DefineProperty(cx, global, "globalProp", vobj, CHECK(JS_DefineProperty(cx, global, "globalProp", obj, JSPROP_ENUMERATE,
JS_PropertyStub, JS_StrictPropertyStub, JS_PropertyStub, JS_StrictPropertyStub));
JSPROP_ENUMERATE));
CHECK(JS_DefineProperty(cx, obj, "prop", JSVAL_VOID, CHECK(JS_DefineProperty(cx, obj, "prop", JS::UndefinedHandleValue, JSPROP_SHARED,
NativeGet, JS_StrictPropertyStub, NativeGet, JS_StrictPropertyStub));
JSPROP_SHARED));
EXEC("'use strict'; \n" EXEC("'use strict'; \n"
"var error, passed = false; \n" "var error, passed = false; \n"
@ -72,7 +69,7 @@ BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
// shell can't. // shell can't.
JS_ASSERT(JS_GetClass(global)->resolve == &JS_ResolveStub); JS_ASSERT(JS_GetClass(global)->resolve == &JS_ResolveStub);
CHECK(JS_DefineProperty(cx, global, "HOTLOOP", INT_TO_JSVAL(8), nullptr, nullptr, 0)); CHECK(JS_DefineProperty(cx, global, "HOTLOOP", 8, 0));
EXEC("var n = 0;\n" EXEC("var n = 0;\n"
"var global = this;\n" "var global = this;\n"
"function f() { n++; }\n" "function f() { n++; }\n"

Просмотреть файл

@ -3100,15 +3100,64 @@ DefineSelfHostedProperty(JSContext *cx,
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JSObject *objArg, const char *name, jsval valueArg, JS_DefineProperty(JSContext *cx, HandleObject obj, const char *name, HandleValue value,
PropertyOp getter, JSStrictPropertyOp setter, unsigned attrs) unsigned attrs,
PropertyOp getter /* = nullptr */, JSStrictPropertyOp setter /* = nullptr */)
{ {
RootedObject obj(cx, objArg);
RootedValue value(cx, valueArg);
return DefineProperty(cx, obj, name, value, GetterWrapper(getter), SetterWrapper(setter), return DefineProperty(cx, obj, name, value, GetterWrapper(getter), SetterWrapper(setter),
attrs, 0); attrs, 0);
} }
JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, HandleObject obj, const char *name, HandleObject valueArg,
unsigned attrs,
PropertyOp getter /* = nullptr */, JSStrictPropertyOp setter /* = nullptr */)
{
RootedValue value(cx, ObjectValue(*valueArg));
return DefineProperty(cx, obj, name, value, GetterWrapper(getter), SetterWrapper(setter),
attrs, 0);
}
JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, HandleObject obj, const char *name, HandleString valueArg,
unsigned attrs,
PropertyOp getter /* = nullptr */, JSStrictPropertyOp setter /* = nullptr */)
{
RootedValue value(cx, StringValue(valueArg));
return DefineProperty(cx, obj, name, value, GetterWrapper(getter), SetterWrapper(setter),
attrs, 0);
}
JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, HandleObject obj, const char *name, int32_t valueArg,
unsigned attrs,
PropertyOp getter /* = nullptr */, JSStrictPropertyOp setter /* = nullptr */)
{
Value value = Int32Value(valueArg);
return DefineProperty(cx, obj, name, HandleValue::fromMarkedLocation(&value),
GetterWrapper(getter), SetterWrapper(setter), attrs, 0);
}
JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, HandleObject obj, const char *name, uint32_t valueArg,
unsigned attrs,
PropertyOp getter /* = nullptr */, JSStrictPropertyOp setter /* = nullptr */)
{
Value value = UINT_TO_JSVAL(valueArg);
return DefineProperty(cx, obj, name, HandleValue::fromMarkedLocation(&value),
GetterWrapper(getter), SetterWrapper(setter), attrs, 0);
}
JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, HandleObject obj, const char *name, double valueArg,
unsigned attrs,
PropertyOp getter /* = nullptr */, JSStrictPropertyOp setter /* = nullptr */)
{
Value value = NumberValue(valueArg);
return DefineProperty(cx, obj, name, HandleValue::fromMarkedLocation(&value),
GetterWrapper(getter), SetterWrapper(setter), attrs, 0);
}
static bool static bool
DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen, DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
const Value &value_, PropertyOp getter, StrictPropertyOp setter, unsigned attrs, const Value &value_, PropertyOp getter, StrictPropertyOp setter, unsigned attrs,

Просмотреть файл

@ -2763,8 +2763,34 @@ extern JS_PUBLIC_API(bool)
JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps);
extern JS_PUBLIC_API(bool) extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value,
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); unsigned attrs,
JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value,
unsigned attrs,
JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value,
unsigned attrs,
JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value,
unsigned attrs,
JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value,
unsigned attrs,
JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value,
unsigned attrs,
JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
extern JS_PUBLIC_API(bool) extern JS_PUBLIC_API(bool)
JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,

Просмотреть файл

@ -272,13 +272,11 @@ JS_TraceShapeCycleCollectorChildren(JSTracer *trc, void *shape)
static bool static bool
DefineHelpProperty(JSContext *cx, HandleObject obj, const char *prop, const char *value) DefineHelpProperty(JSContext *cx, HandleObject obj, const char *prop, const char *value)
{ {
JSAtom *atom = Atomize(cx, value, strlen(value)); RootedAtom atom(cx, Atomize(cx, value, strlen(value)));
if (!atom) if (!atom)
return false; return false;
jsval v = STRING_TO_JSVAL(atom); return JS_DefineProperty(cx, obj, prop, atom, JSPROP_READONLY | JSPROP_PERMANENT,
return JS_DefineProperty(cx, obj, prop, v, JS_PropertyStub, JS_StrictPropertyStub);
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_READONLY | JSPROP_PERMANENT);
} }
JS_FRIEND_API(bool) JS_FRIEND_API(bool)

Просмотреть файл

@ -1600,8 +1600,9 @@ js_InitMathClass(JSContext *cx, HandleObject obj)
if (!Math) if (!Math)
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, obj, js_Math_str, OBJECT_TO_JSVAL(Math), if (!JS_DefineProperty(cx, obj, js_Math_str, Math, 0,
JS_PropertyStub, JS_StrictPropertyStub, 0)) { JS_PropertyStub, JS_StrictPropertyStub))
{
return nullptr; return nullptr;
} }

Просмотреть файл

@ -879,8 +879,8 @@ js_InitJSONClass(JSContext *cx, HandleObject obj)
if (!JSON) if (!JSON)
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, global, js_JSON_str, OBJECT_TO_JSVAL(JSON), if (!JS_DefineProperty(cx, global, js_JSON_str, JSON, 0,
JS_PropertyStub, JS_StrictPropertyStub, 0)) JS_PropertyStub, JS_StrictPropertyStub))
return nullptr; return nullptr;
if (!JS_DefineFunctions(cx, JSON, json_static_methods)) if (!JS_DefineFunctions(cx, JSON, json_static_methods))

Просмотреть файл

@ -3285,8 +3285,8 @@ js_InitProxyClass(JSContext *cx, HandleObject obj)
if (!JS_DefineFunctions(cx, ctor, static_methods)) if (!JS_DefineFunctions(cx, ctor, static_methods))
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, obj, "Proxy", OBJECT_TO_JSVAL(ctor), if (!JS_DefineProperty(cx, obj, "Proxy", ctor, 0,
JS_PropertyStub, JS_StrictPropertyStub, 0)) { JS_PropertyStub, JS_StrictPropertyStub)) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -3338,8 +3338,8 @@ JS_InitReflect(JSContext *cx, HandleObject obj)
if (!Reflect) if (!Reflect)
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, obj, "Reflect", OBJECT_TO_JSVAL(Reflect), if (!JS_DefineProperty(cx, obj, "Reflect", Reflect, 0,
JS_PropertyStub, JS_StrictPropertyStub, 0)) { JS_PropertyStub, JS_StrictPropertyStub)) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -246,8 +246,8 @@ RegisterPerfMeasurement(JSContext *cx, HandleObject globalArg)
return 0; return 0;
for (const pm_const *c = pm_consts; c->name; c++) { for (const pm_const *c = pm_consts; c->name; c++) {
if (!JS_DefineProperty(cx, ctor, c->name, INT_TO_JSVAL(c->value), if (!JS_DefineProperty(cx, ctor, c->name, c->value, PM_CATTRS,
JS_PropertyStub, JS_StrictPropertyStub, PM_CATTRS)) JS_PropertyStub, JS_StrictPropertyStub))
return 0; return 0;
} }

Просмотреть файл

@ -5016,7 +5016,7 @@ env_enumerate(JSContext *cx, HandleObject obj)
{ {
static bool reflected; static bool reflected;
char **evp, *name, *value; char **evp, *name, *value;
JSString *valstr; RootedString valstr(cx);
bool ok; bool ok;
if (reflected) if (reflected)
@ -5028,8 +5028,7 @@ env_enumerate(JSContext *cx, HandleObject obj)
continue; continue;
*value++ = '\0'; *value++ = '\0';
valstr = JS_NewStringCopyZ(cx, value); valstr = JS_NewStringCopyZ(cx, value);
ok = valstr && JS_DefineProperty(cx, obj, name, STRING_TO_JSVAL(valstr), ok = valstr && JS_DefineProperty(cx, obj, name, valstr, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
value[-1] = '='; value[-1] = '=';
if (!ok) if (!ok)
return false; return false;
@ -5055,10 +5054,8 @@ env_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
RootedString valstr(cx, JS_NewStringCopyZ(cx, value)); RootedString valstr(cx, JS_NewStringCopyZ(cx, value));
if (!valstr) if (!valstr)
return false; return false;
if (!JS_DefineProperty(cx, obj, name, STRING_TO_JSVAL(valstr), if (!JS_DefineProperty(cx, obj, name, valstr, JSPROP_ENUMERATE))
nullptr, nullptr, JSPROP_ENUMERATE)) {
return false; return false;
}
objp.set(obj); objp.set(obj);
} }
return true; return true;
@ -5659,8 +5656,7 @@ BindScriptArgs(JSContext *cx, JSObject *obj_, OptionParser *op)
if (!scriptArgs) if (!scriptArgs)
return false; return false;
if (!JS_DefineProperty(cx, obj, "scriptArgs", OBJECT_TO_JSVAL(scriptArgs), if (!JS_DefineProperty(cx, obj, "scriptArgs", scriptArgs, 0))
nullptr, nullptr, 0))
return false; return false;
for (size_t i = 0; !msr.empty(); msr.popFront(), ++i) { for (size_t i = 0; !msr.empty(); msr.popFront(), ++i) {

Просмотреть файл

@ -721,11 +721,8 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx,
RootedObject locationObj(aCx, locationHolder->GetJSObject()); RootedObject locationObj(aCx, locationHolder->GetJSObject());
NS_ENSURE_TRUE(locationObj, nullptr); NS_ENSURE_TRUE(locationObj, nullptr);
if (!JS_DefineProperty(aCx, obj, "__LOCATION__", if (!JS_DefineProperty(aCx, obj, "__LOCATION__", locationObj, 0))
ObjectValue(*locationObj),
nullptr, nullptr, 0)) {
return nullptr; return nullptr;
}
} }
nsAutoCString nativePath; nsAutoCString nativePath;
@ -734,12 +731,11 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx,
// Expose the URI from which the script was imported through a special // Expose the URI from which the script was imported through a special
// variable that we insert into the JSM. // variable that we insert into the JSM.
JSString *exposedUri = JS_NewStringCopyN(aCx, nativePath.get(), RootedString exposedUri(aCx, JS_NewStringCopyN(aCx, nativePath.get(), nativePath.Length()));
nativePath.Length()); NS_ENSURE_TRUE(exposedUri, nullptr);
if (!JS_DefineProperty(aCx, obj, "__URI__",
STRING_TO_JSVAL(exposedUri), nullptr, nullptr, 0)) { if (!JS_DefineProperty(aCx, obj, "__URI__", exposedUri, 0))
return nullptr; return nullptr;
}
if (createdNewGlobal) { if (createdNewGlobal) {
RootedObject global(aCx, holder->GetJSObject()); RootedObject global(aCx, holder->GetJSObject());

Просмотреть файл

@ -3431,12 +3431,12 @@ nsXPCComponents_Utils::GetJSEngineTelemetryValue(JSContext *cx, MutableHandleVal
size_t i = JS_SetProtoCalled(cx); size_t i = JS_SetProtoCalled(cx);
RootedValue v(cx, DoubleValue(i)); RootedValue v(cx, DoubleValue(i));
if (!JS_DefineProperty(cx, obj, "setProto", v, nullptr, nullptr, attrs)) if (!JS_DefineProperty(cx, obj, "setProto", v, attrs))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
i = JS_GetCustomIteratorCount(cx); i = JS_GetCustomIteratorCount(cx);
v.setDouble(i); v.setDouble(i);
if (!JS_DefineProperty(cx, obj, "customIter", v, nullptr, nullptr, attrs)) if (!JS_DefineProperty(cx, obj, "customIter", v, attrs))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
rval.setObject(*obj); rval.setObject(*obj);

Просмотреть файл

@ -122,10 +122,10 @@ xpc_qsDefineQuickStubs(JSContext *cx, JSObject *protoArg, unsigned flags,
for ( ; ps < ps_end; ++ps) { for ( ; ps < ps_end; ++ps) {
if (!JS_DefineProperty(cx, proto, if (!JS_DefineProperty(cx, proto,
stringTable + ps->name_index, stringTable + ps->name_index,
JSVAL_VOID, JS::UndefinedHandleValue,
flags | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS,
(JSPropertyOp)ps->getter, (JSPropertyOp)ps->getter,
(JSStrictPropertyOp)ps->setter, (JSStrictPropertyOp)ps->setter))
flags | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS))
return false; return false;
} }

Просмотреть файл

@ -802,7 +802,7 @@ env_enumerate(JSContext *cx, HandleObject obj)
{ {
static bool reflected; static bool reflected;
char **evp, *name, *value; char **evp, *name, *value;
JSString *valstr; RootedString valstr(cx);
bool ok; bool ok;
if (reflected) if (reflected)
@ -814,12 +814,7 @@ env_enumerate(JSContext *cx, HandleObject obj)
continue; continue;
*value++ = '\0'; *value++ = '\0';
valstr = JS_NewStringCopyZ(cx, value); valstr = JS_NewStringCopyZ(cx, value);
if (!valstr) { ok = valstr ? JS_DefineProperty(cx, obj, name, valstr, JSPROP_ENUMERATE) : false;
ok = false;
} else {
ok = JS_DefineProperty(cx, obj, name, STRING_TO_JSVAL(valstr),
nullptr, nullptr, JSPROP_ENUMERATE);
}
value[-1] = '='; value[-1] = '=';
if (!ok) if (!ok)
return false; return false;
@ -1094,10 +1089,8 @@ ProcessArgs(JSContext *cx, JS::Handle<JSObject*> obj, char **argv, int argc, XPC
argsObj = JS_NewArrayObject(cx, 0); argsObj = JS_NewArrayObject(cx, 0);
if (!argsObj) if (!argsObj)
return 1; return 1;
if (!JS_DefineProperty(cx, obj, "arguments", OBJECT_TO_JSVAL(argsObj), if (!JS_DefineProperty(cx, obj, "arguments", argsObj, 0))
nullptr, nullptr, 0)) {
return 1; return 1;
}
for (size_t j = 0, length = argc - i; j < length; j++) { for (size_t j = 0, length = argc - i; j < length; j++) {
JSString *str = JS_NewStringCopyZ(cx, argv[i++]); JSString *str = JS_NewStringCopyZ(cx, argv[i++]);
@ -1585,8 +1578,8 @@ XRE_XPCShellMain(int argc, char **argv, char **envp)
if (GetCurrentWorkingDirectory(workingDirectory)) if (GetCurrentWorkingDirectory(workingDirectory))
gWorkingDirectory = &workingDirectory; gWorkingDirectory = &workingDirectory;
JS_DefineProperty(cx, glob, "__LOCATION__", JSVAL_VOID, JS_DefineProperty(cx, glob, "__LOCATION__", JS::UndefinedHandleValue, 0,
GetLocationProperty, nullptr, 0); GetLocationProperty, nullptr);
result = ProcessArgs(cx, glob, argv, argc, &dirprovider); result = ProcessArgs(cx, glob, argv, argc, &dirprovider);

Просмотреть файл

@ -766,8 +766,7 @@ nsAppStartup::GetStartupInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aRetva
PRTime prStamp = ComputeAbsoluteTimestamp(absNow, now, stamp) PRTime prStamp = ComputeAbsoluteTimestamp(absNow, now, stamp)
/ PR_USEC_PER_MSEC; / PR_USEC_PER_MSEC;
JS::Rooted<JSObject*> date(aCx, JS_NewDateObjectMsec(aCx, prStamp)); JS::Rooted<JSObject*> date(aCx, JS_NewDateObjectMsec(aCx, prStamp));
JS_DefineProperty(aCx, obj, StartupTimeline::Describe(ev), JS_DefineProperty(aCx, obj, StartupTimeline::Describe(ev), date, JSPROP_ENUMERATE);
OBJECT_TO_JSVAL(date), nullptr, nullptr, JSPROP_ENUMERATE);
} else { } else {
Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, ev); Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, ev);
} }

Просмотреть файл

@ -817,16 +817,16 @@ ReflectHistogramAndSamples(JSContext *cx, JS::Handle<JSObject*> obj, Histogram *
return REFLECT_CORRUPT; return REFLECT_CORRUPT;
} }
if (!(JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), nullptr, nullptr, JSPROP_ENUMERATE) if (!(JS_DefineProperty(cx, obj, "min", h->declared_min(), JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), nullptr, nullptr, JSPROP_ENUMERATE) && JS_DefineProperty(cx, obj, "max", h->declared_max(), JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "histogram_type", INT_TO_JSVAL(h->histogram_type()), nullptr, nullptr, JSPROP_ENUMERATE) && JS_DefineProperty(cx, obj, "histogram_type", h->histogram_type(), JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), nullptr, nullptr, JSPROP_ENUMERATE))) { && JS_DefineProperty(cx, obj, "sum", double(ss.sum()), JSPROP_ENUMERATE))) {
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
if (h->histogram_type() == Histogram::HISTOGRAM) { if (h->histogram_type() == Histogram::HISTOGRAM) {
if (!(JS_DefineProperty(cx, obj, "log_sum", DOUBLE_TO_JSVAL(ss.log_sum()), nullptr, nullptr, JSPROP_ENUMERATE) if (!(JS_DefineProperty(cx, obj, "log_sum", ss.log_sum(), JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "log_sum_squares", DOUBLE_TO_JSVAL(ss.log_sum_squares()), nullptr, nullptr, JSPROP_ENUMERATE))) { && JS_DefineProperty(cx, obj, "log_sum_squares", ss.log_sum_squares(), JSPROP_ENUMERATE))) {
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
} else { } else {
@ -836,8 +836,8 @@ ReflectHistogramAndSamples(JSContext *cx, JS::Handle<JSObject*> obj, Histogram *
// Cast to avoid implicit truncation warnings. // Cast to avoid implicit truncation warnings.
uint32_t lo = static_cast<uint32_t>(sum_squares); uint32_t lo = static_cast<uint32_t>(sum_squares);
uint32_t hi = static_cast<uint32_t>(sum_squares >> 32); uint32_t hi = static_cast<uint32_t>(sum_squares >> 32);
if (!(JS_DefineProperty(cx, obj, "sum_squares_lo", INT_TO_JSVAL(lo), nullptr, nullptr, JSPROP_ENUMERATE) if (!(JS_DefineProperty(cx, obj, "sum_squares_lo", lo, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "sum_squares_hi", INT_TO_JSVAL(hi), nullptr, nullptr, JSPROP_ENUMERATE))) { && JS_DefineProperty(cx, obj, "sum_squares_hi", hi, JSPROP_ENUMERATE))) {
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
} }
@ -848,8 +848,7 @@ ReflectHistogramAndSamples(JSContext *cx, JS::Handle<JSObject*> obj, Histogram *
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
if (!(FillRanges(cx, rarray, h) if (!(FillRanges(cx, rarray, h)
&& JS_DefineProperty(cx, obj, "ranges", OBJECT_TO_JSVAL(rarray), && JS_DefineProperty(cx, obj, "ranges", rarray, JSPROP_ENUMERATE))) {
nullptr, nullptr, JSPROP_ENUMERATE))) {
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
@ -857,8 +856,7 @@ ReflectHistogramAndSamples(JSContext *cx, JS::Handle<JSObject*> obj, Histogram *
if (!counts_array) { if (!counts_array) {
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
if (!JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array), if (!JS_DefineProperty(cx, obj, "counts", counts_array, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
return REFLECT_FAILURE; return REFLECT_FAILURE;
} }
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
@ -1291,10 +1289,8 @@ TelemetryImpl::ReflectSQL(const SlowSQLEntryType *entry,
} }
return (JS_SetElement(cx, arrayObj, 0, stat->hitCount) return (JS_SetElement(cx, arrayObj, 0, stat->hitCount)
&& JS_SetElement(cx, arrayObj, 1, stat->totalTime) && JS_SetElement(cx, arrayObj, 1, stat->totalTime)
&& JS_DefineProperty(cx, obj, && JS_DefineProperty(cx, obj, sql.BeginReading(), arrayObj,
sql.BeginReading(), JSPROP_ENUMERATE));
OBJECT_TO_JSVAL(arrayObj),
nullptr, nullptr, JSPROP_ENUMERATE));
} }
bool bool
@ -1329,8 +1325,7 @@ TelemetryImpl::AddSQLInfo(JSContext *cx, JS::Handle<JSObject*> rootObj, bool mai
return JS_DefineProperty(cx, rootObj, return JS_DefineProperty(cx, rootObj,
mainThread ? "mainThread" : "otherThreads", mainThread ? "mainThread" : "otherThreads",
OBJECT_TO_JSVAL(statsObj), statsObj, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
} }
nsresult nsresult
@ -1615,8 +1610,8 @@ TelemetryImpl::GetHistogramSnapshots(JSContext *cx, JS::MutableHandle<JS::Value>
case REFLECT_FAILURE: case REFLECT_FAILURE:
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
case REFLECT_OK: case REFLECT_OK:
if (!JS_DefineProperty(cx, root_obj, h->histogram_name().c_str(), if (!JS_DefineProperty(cx, root_obj, h->histogram_name().c_str(), hobj,
OBJECT_TO_JSVAL(hobj), nullptr, nullptr, JSPROP_ENUMERATE)) { JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }
@ -1675,10 +1670,8 @@ TelemetryImpl::AddonHistogramReflector(AddonHistogramEntryType *entry,
return false; return false;
case REFLECT_OK: case REFLECT_OK:
const nsACString &histogramName = entry->GetKey(); const nsACString &histogramName = entry->GetKey();
if (!JS_DefineProperty(cx, obj, if (!JS_DefineProperty(cx, obj, PromiseFlatCString(histogramName).get(),
PromiseFlatCString(histogramName).get(), snapshot, JSPROP_ENUMERATE)) {
OBJECT_TO_JSVAL(snapshot), nullptr, nullptr,
JSPROP_ENUMERATE)) {
return false; return false;
} }
break; break;
@ -1698,10 +1691,8 @@ TelemetryImpl::AddonReflector(AddonEntryType *entry,
AddonHistogramMapType *map = entry->mData; AddonHistogramMapType *map = entry->mData;
if (!(map->ReflectIntoJS(AddonHistogramReflector, cx, subobj) if (!(map->ReflectIntoJS(AddonHistogramReflector, cx, subobj)
&& JS_DefineProperty(cx, obj, && JS_DefineProperty(cx, obj, PromiseFlatCString(addonId).get(),
PromiseFlatCString(addonId).get(), subobj, JSPROP_ENUMERATE))) {
OBJECT_TO_JSVAL(subobj), nullptr, nullptr,
JSPROP_ENUMERATE))) {
return false; return false;
} }
return true; return true;
@ -1787,22 +1778,19 @@ TelemetryImpl::GetChromeHangs(JSContext *cx, JS::MutableHandle<JS::Value> ret)
} }
bool ok = JS_DefineProperty(cx, fullReportObj, "durations", bool ok = JS_DefineProperty(cx, fullReportObj, "durations",
OBJECT_TO_JSVAL(durationArray), durationArray, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
if (!ok) { if (!ok) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
ok = JS_DefineProperty(cx, fullReportObj, "systemUptime", ok = JS_DefineProperty(cx, fullReportObj, "systemUptime",
OBJECT_TO_JSVAL(systemUptimeArray), systemUptimeArray, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
if (!ok) { if (!ok) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
ok = JS_DefineProperty(cx, fullReportObj, "firefoxUptime", ok = JS_DefineProperty(cx, fullReportObj, "firefoxUptime",
OBJECT_TO_JSVAL(firefoxUptimeArray), firefoxUptimeArray, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
if (!ok) { if (!ok) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1834,9 +1822,8 @@ CreateJSStackObject(JSContext *cx, const CombinedStacks &stacks) {
if (!moduleArray) { if (!moduleArray) {
return nullptr; return nullptr;
} }
bool ok = JS_DefineProperty(cx, ret, "memoryMap", bool ok = JS_DefineProperty(cx, ret, "memoryMap", moduleArray,
OBJECT_TO_JSVAL(moduleArray), JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
if (!ok) { if (!ok) {
return nullptr; return nullptr;
} }
@ -1880,9 +1867,7 @@ CreateJSStackObject(JSContext *cx, const CombinedStacks &stacks) {
if (!reportArray) { if (!reportArray) {
return nullptr; return nullptr;
} }
ok = JS_DefineProperty(cx, ret, "stacks", ok = JS_DefineProperty(cx, ret, "stacks", reportArray, JSPROP_ENUMERATE);
OBJECT_TO_JSVAL(reportArray),
nullptr, nullptr, JSPROP_ENUMERATE);
if (!ok) { if (!ok) {
return nullptr; return nullptr;
} }
@ -2022,25 +2007,20 @@ CreateJSTimeHistogram(JSContext* cx, const Telemetry::TimeHistogram& time)
return nullptr; return nullptr;
} }
if (!JS_DefineProperty(cx, ret, "min", if (!JS_DefineProperty(cx, ret, "min", time.GetBucketMin(0),
UINT_TO_JSVAL(time.GetBucketMin(0)), JSPROP_ENUMERATE) ||
nullptr, nullptr, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, ret, "max", !JS_DefineProperty(cx, ret, "max",
UINT_TO_JSVAL(time.GetBucketMax( time.GetBucketMax(ArrayLength(time) - 1),
ArrayLength(time) - 1)), JSPROP_ENUMERATE) ||
nullptr, nullptr, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, ret, "histogram_type", !JS_DefineProperty(cx, ret, "histogram_type",
INT_TO_JSVAL(nsITelemetry::HISTOGRAM_EXPONENTIAL), nsITelemetry::HISTOGRAM_EXPONENTIAL,
nullptr, nullptr, JSPROP_ENUMERATE)) { JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
// TODO: calculate "sum", "log_sum", and "log_sum_squares" // TODO: calculate "sum", "log_sum", and "log_sum_squares"
if (!JS_DefineProperty(cx, ret, "sum", INT_TO_JSVAL(0), if (!JS_DefineProperty(cx, ret, "sum", 0, JSPROP_ENUMERATE) ||
nullptr, nullptr, JSPROP_ENUMERATE) || !JS_DefineProperty(cx, ret, "log_sum", 0.0, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, ret, "log_sum", DOUBLE_TO_JSVAL(0.0), !JS_DefineProperty(cx, ret, "log_sum_squares", 0.0, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, ret, "log_sum_squares", DOUBLE_TO_JSVAL(0.0),
nullptr, nullptr, JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
@ -2063,10 +2043,8 @@ CreateJSTimeHistogram(JSContext* cx, const Telemetry::TimeHistogram& time)
return nullptr; return nullptr;
} }
} }
if (!JS_DefineProperty(cx, ret, "ranges", OBJECT_TO_JSVAL(ranges), if (!JS_DefineProperty(cx, ret, "ranges", ranges, JSPROP_ENUMERATE) ||
nullptr, nullptr, JSPROP_ENUMERATE) || !JS_DefineProperty(cx, ret, "counts", counts, JSPROP_ENUMERATE)) {
!JS_DefineProperty(cx, ret, "counts", OBJECT_TO_JSVAL(counts),
nullptr, nullptr, JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
return ret; return ret;
@ -2095,10 +2073,8 @@ CreateJSHangHistogram(JSContext* cx, const Telemetry::HangHistogram& hang)
JS::RootedObject time(cx, CreateJSTimeHistogram(cx, hang)); JS::RootedObject time(cx, CreateJSTimeHistogram(cx, hang));
if (!time || if (!time ||
!JS_DefineProperty(cx, ret, "stack", OBJECT_TO_JSVAL(stack), !JS_DefineProperty(cx, ret, "stack", stack, JSPROP_ENUMERATE) ||
nullptr, nullptr, JSPROP_ENUMERATE) || !JS_DefineProperty(cx, ret, "histogram", time, JSPROP_ENUMERATE)) {
!JS_DefineProperty(cx, ret, "histogram", OBJECT_TO_JSVAL(time),
nullptr, nullptr, JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
return ret; return ret;
@ -2113,15 +2089,13 @@ CreateJSThreadHangStats(JSContext* cx, const Telemetry::ThreadHangStats& thread)
} }
JS::RootedString name(cx, JS_NewStringCopyZ(cx, thread.GetName())); JS::RootedString name(cx, JS_NewStringCopyZ(cx, thread.GetName()));
if (!name || if (!name ||
!JS_DefineProperty(cx, ret, "name", STRING_TO_JSVAL(name), !JS_DefineProperty(cx, ret, "name", name, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
JS::RootedObject activity(cx, CreateJSTimeHistogram(cx, thread.mActivity)); JS::RootedObject activity(cx, CreateJSTimeHistogram(cx, thread.mActivity));
if (!activity || if (!activity ||
!JS_DefineProperty(cx, ret, "activity", OBJECT_TO_JSVAL(activity), !JS_DefineProperty(cx, ret, "activity", activity, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
@ -2135,8 +2109,7 @@ CreateJSThreadHangStats(JSContext* cx, const Telemetry::ThreadHangStats& thread)
return nullptr; return nullptr;
} }
} }
if (!JS_DefineProperty(cx, ret, "hangs", OBJECT_TO_JSVAL(hangs), if (!JS_DefineProperty(cx, ret, "hangs", hangs, JSPROP_ENUMERATE)) {
nullptr, nullptr, JSPROP_ENUMERATE)) {
return nullptr; return nullptr;
} }
return ret; return ret;

Просмотреть файл

@ -16,7 +16,7 @@ JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, JS::
if (!mOk) if (!mOk)
return; return;
mOk = JS_DefineProperty(mCx, aObject, name, OBJECT_TO_JSVAL(aValue), nullptr, nullptr, JSPROP_ENUMERATE); mOk = JS_DefineProperty(mCx, aObject, name, aValue, JSPROP_ENUMERATE);
} }
void void
@ -25,7 +25,7 @@ JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, int
if (!mOk) if (!mOk)
return; return;
mOk = JS_DefineProperty(mCx, aObject, name, INT_TO_JSVAL(value), nullptr, nullptr, JSPROP_ENUMERATE); mOk = JS_DefineProperty(mCx, aObject, name, value, JSPROP_ENUMERATE);
} }
void void
@ -34,7 +34,7 @@ JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, doub
if (!mOk) if (!mOk)
return; return;
mOk = JS_DefineProperty(mCx, aObject, name, DOUBLE_TO_JSVAL(value), nullptr, nullptr, JSPROP_ENUMERATE); mOk = JS_DefineProperty(mCx, aObject, name, value, JSPROP_ENUMERATE);
} }
void void
@ -44,14 +44,14 @@ JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, nsAS
return; return;
const nsString &flat = PromiseFlatString(value); const nsString &flat = PromiseFlatString(value);
JSString *string = JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()), flat.Length()); JS::RootedString string(mCx, JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()), flat.Length()));
if (!string) if (!string)
mOk = false; mOk = false;
if (!mOk) if (!mOk)
return; return;
mOk = JS_DefineProperty(mCx, aObject, name, STRING_TO_JSVAL(string), nullptr, nullptr, JSPROP_ENUMERATE); mOk = JS_DefineProperty(mCx, aObject, name, string, JSPROP_ENUMERATE);
} }
void void
@ -60,13 +60,13 @@ JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, cons
if (!mOk) if (!mOk)
return; return;
JSString *string = JS_InternStringN(mCx, value, valueLength); JS::RootedString string(mCx, JS_InternStringN(mCx, value, valueLength));
if (!string) { if (!string) {
mOk = false; mOk = false;
return; return;
} }
mOk = JS_DefineProperty(mCx, (JSObject*)aObject, name, STRING_TO_JSVAL(string), nullptr, nullptr, JSPROP_ENUMERATE); } mOk = JS_DefineProperty(mCx, aObject, name, string, JSPROP_ENUMERATE); }
void void
JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, const char *value) JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, const char *value)

Просмотреть файл

@ -18,8 +18,7 @@ InfoObject::DefineProperty(const char *name, int value)
if (!mOk) if (!mOk)
return; return;
mOk = JS_DefineProperty(mCx, mObj, name, INT_TO_JSVAL(value), mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
} }
void void
@ -29,15 +28,15 @@ InfoObject::DefineProperty(const char *name, nsAString &value)
return; return;
const nsString &flat = PromiseFlatString(value); const nsString &flat = PromiseFlatString(value);
JSString *string = JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()), flat.Length()); JS::Rooted<JSString*> string(mCx, JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()),
flat.Length()));
if (!string) if (!string)
mOk = false; mOk = false;
if (!mOk) if (!mOk)
return; return;
mOk = JS_DefineProperty(mCx, mObj, name, STRING_TO_JSVAL(string), mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE);
nullptr, nullptr, JSPROP_ENUMERATE);
} }
void void