bug 723510 - Workers: double-error reporting in location.toString and incorrect assumption about JS_GetInstancePrivate. r=bent

This commit is contained in:
Igor Bukanov 2012-02-03 19:00:08 +01:00
Родитель c63af69429
Коммит 2d9a84ce93
10 изменённых файлов: 73 добавлений и 149 удалений

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

@ -73,15 +73,13 @@ bool
EnsureObjectIsEventTarget(JSContext* aCx, JSObject* aObj, char* aFunctionName) EnsureObjectIsEventTarget(JSContext* aCx, JSObject* aObj, char* aFunctionName)
{ {
JSClass* classPtr = JS_GET_CLASS(aCx, aObj); JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr && if (ClassIsWorker(classPtr) || ClassIsWorkerGlobalScope(classPtr) ||
(ClassIsWorker(classPtr) || ClassIsWorkerGlobalScope(classPtr) || ClassIsXMLHttpRequest(classPtr)) {
ClassIsXMLHttpRequest(classPtr))) {
return true; return true;
} }
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
"EventTarget", aFunctionName, "EventTarget", aFunctionName, classPtr->name);
classPtr ? classPtr->name : "object");
return false; return false;
} }

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

@ -214,20 +214,13 @@ protected:
static Event* static Event*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL;
if (aObj) {
Event* priv = GetPrivate(aCx, aObj); Event* priv = GetPrivate(aCx, aObj);
if (priv) { if (priv) {
return priv; return priv;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); JS_GET_CLASS(aCx, aObj)->name);
return NULL; return NULL;
} }
@ -533,20 +526,14 @@ private:
static MessageEvent* static MessageEvent*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
// JS_GetInstancePrivate is ok to be called with a null aObj, so this should JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
// be too.
JSClass* classPtr = NULL;
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (IsThisClass(classPtr)) { if (IsThisClass(classPtr)) {
return GetJSPrivateSafeish<MessageEvent>(aCx, aObj); return GetJSPrivateSafeish<MessageEvent>(aCx, aObj);
} }
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); classPtr->name);
return NULL; return NULL;
} }
@ -764,20 +751,14 @@ private:
static ErrorEvent* static ErrorEvent*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
// JS_GetInstancePrivate is ok to be called with a null aObj, so this should JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
// be too.
JSClass* classPtr = NULL;
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (IsThisClass(classPtr)) { if (IsThisClass(classPtr)) {
return GetJSPrivateSafeish<ErrorEvent>(aCx, aObj); return GetJSPrivateSafeish<ErrorEvent>(aCx, aObj);
} }
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); classPtr->name);
return NULL; return NULL;
} }
@ -958,18 +939,14 @@ private:
static ProgressEvent* static ProgressEvent*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL; JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass) { if (classPtr == &sClass) {
return GetJSPrivateSafeish<ProgressEvent>(aCx, aObj); return GetJSPrivateSafeish<ProgressEvent>(aCx, aObj);
} }
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); classPtr->name);
return NULL; return NULL;
} }

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

@ -125,11 +125,11 @@ private:
return false; return false;
} }
JSClass* classPtr; JSClass* classPtr = JS_GET_CLASS(aCx, obj);
if (!obj || ((classPtr = JS_GET_CLASS(aCx, obj)) != &sClass)) { if (classPtr != &sClass) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, "toString", JSMSG_INCOMPATIBLE_PROTO, sClass.name, "toString",
classPtr ? classPtr->name : "object"); classPtr->name);
return false; return false;
} }
@ -166,12 +166,10 @@ private:
JSClass* classPtr = JS_GET_CLASS(aCx, aObj); JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr != &sClass || if (classPtr != &sClass || !GetJSPrivateSafeish<DOMException>(aCx, aObj)) {
!GetJSPrivateSafeish<DOMException>(aCx, aObj)) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, JSMSG_INCOMPATIBLE_PROTO, sClass.name,
sProperties[slot].name, sProperties[slot].name, classPtr->name);
classPtr ? classPtr->name : "object");
return false; return false;
} }
@ -344,12 +342,10 @@ private:
JSClass* classPtr = JS_GET_CLASS(aCx, aObj); JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr != &sClass || if (classPtr != &sClass || !GetJSPrivateSafeish<FileException>(aCx, aObj)) {
!GetJSPrivateSafeish<FileException>(aCx, aObj)) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, JSMSG_INCOMPATIBLE_PROTO, sClass.name,
sProperties[slot].name, sProperties[slot].name, classPtr->name);
classPtr ? classPtr->name : "object");
return false; return false;
} }

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

@ -101,20 +101,14 @@ private:
static nsIDOMBlob* static nsIDOMBlob*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL;
if (aObj) {
nsIDOMBlob* blob = GetPrivate(aCx, aObj); nsIDOMBlob* blob = GetPrivate(aCx, aObj);
if (blob) { if (blob) {
return blob; return blob;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "Object"); JS_GET_CLASS(aCx, aObj)->name);
return NULL; return NULL;
} }
@ -299,19 +293,14 @@ private:
static nsIDOMFile* static nsIDOMFile*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL;
if (aObj) {
nsIDOMFile* file = GetPrivate(aCx, aObj); nsIDOMFile* file = GetPrivate(aCx, aObj);
if (file) { if (file) {
return file; return file;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "Object"); JS_GET_CLASS(aCx, aObj)->name);
return NULL; return NULL;
} }

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

@ -78,19 +78,17 @@ EnsureSucceededOrThrow(JSContext* aCx, nsresult rv)
inline nsIDOMBlob* inline nsIDOMBlob*
GetDOMBlobFromJSObject(JSContext* aCx, JSObject* aObj) { GetDOMBlobFromJSObject(JSContext* aCx, JSObject* aObj) {
JSClass* classPtr = NULL; // aObj can be null as JS_ConvertArguments("o") successfully converts JS
// null to a null pointer to JSObject
if (aObj) { if (aObj) {
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aCx, aObj); nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aCx, aObj);
if (blob) { if (blob) {
return blob; return blob;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
} }
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE,
classPtr ? classPtr->name : "Object", "not a Blob."); aObj ? JS_GET_CLASS(aCx, aObj)->name : "Object", "not a Blob.");
return NULL; return NULL;
} }
@ -129,20 +127,14 @@ private:
static FileReaderSyncPrivate* static FileReaderSyncPrivate*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL;
if (aObj) {
FileReaderSyncPrivate* fileReader = GetPrivate(aCx, aObj); FileReaderSyncPrivate* fileReader = GetPrivate(aCx, aObj);
if (fileReader) { if (fileReader) {
return fileReader; return fileReader;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "Object"); JS_GET_CLASS(aCx, aObj)->name);
return NULL; return NULL;
} }

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

@ -148,12 +148,15 @@ private:
ToString(JSContext* aCx, uintN aArgc, jsval* aVp) ToString(JSContext* aCx, uintN aArgc, jsval* aVp)
{ {
JSObject* obj = JS_THIS_OBJECT(aCx, aVp); JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
if (!obj) {
return false;
}
JSClass* classPtr; JSClass* classPtr = JS_GET_CLASS(aCx, obj);
if (!obj || ((classPtr = JS_GET_CLASS(aCx, obj)) != &sClass)) { if (classPtr != &sClass) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, "toString", JSMSG_INCOMPATIBLE_PROTO, sClass.name, "toString",
classPtr ? classPtr->name : "object"); classPtr);
return false; return false;
} }
@ -170,11 +173,11 @@ private:
static JSBool static JSBool
GetProperty(JSContext* aCx, JSObject* aObj, jsid aIdval, jsval* aVp) GetProperty(JSContext* aCx, JSObject* aObj, jsid aIdval, jsval* aVp)
{ {
JSClass* classPtr; JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (!aObj || ((classPtr = JS_GET_CLASS(aCx, aObj)) != &sClass)) { if (classPtr != &sClass) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, "GetProperty", JSMSG_INCOMPATIBLE_PROTO, sClass.name, "GetProperty",
classPtr ? classPtr->name : "object"); classPtr->name);
return false; return false;
} }

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

@ -158,11 +158,11 @@ private:
static JSBool static JSBool
GetProperty(JSContext* aCx, JSObject* aObj, jsid aIdval, jsval* aVp) GetProperty(JSContext* aCx, JSObject* aObj, jsid aIdval, jsval* aVp)
{ {
JSClass* classPtr; JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (!aObj || ((classPtr = JS_GET_CLASS(aCx, aObj)) != &sClass)) { if (classPtr != &sClass) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, "GetProperty", JSMSG_INCOMPATIBLE_PROTO, sClass.name, "GetProperty",
classPtr ? classPtr->name : "object"); classPtr->name);
return false; return false;
} }

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

@ -427,18 +427,13 @@ WorkerPrivate*
Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj, Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
const char* aFunctionName) const char* aFunctionName)
{ {
JSClass* classPtr = NULL; JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass || classPtr == ChromeWorker::Class()) { if (classPtr == &sClass || classPtr == ChromeWorker::Class()) {
return GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj); return GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
} }
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
sClass.name, aFunctionName, sClass.name, aFunctionName, classPtr->name);
classPtr ? classPtr->name : "object");
return NULL; return NULL;
} }

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

@ -722,20 +722,14 @@ private:
static DedicatedWorkerGlobalScope* static DedicatedWorkerGlobalScope*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
// JS_GetInstancePrivate is ok to be called with a null aObj, so this should JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
// be too.
JSClass* classPtr = NULL;
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass) { if (classPtr == &sClass) {
return GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aCx, aObj); return GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aCx, aObj);
} }
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); classPtr->name);
return NULL; return NULL;
} }
@ -833,21 +827,13 @@ WorkerGlobalScope*
WorkerGlobalScope::GetInstancePrivate(JSContext* aCx, JSObject* aObj, WorkerGlobalScope::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
const char* aFunctionName) const char* aFunctionName)
{ {
// JS_GetInstancePrivate is ok to be called with a null aObj, so this should JSClass* classPtr = JS_GET_CLASS(aCx, aObj);
// be too. if (classPtr == &sClass || classPtr == DedicatedWorkerGlobalScope::Class()) {
JSClass* classPtr = NULL;
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass ||
classPtr == DedicatedWorkerGlobalScope::Class()) {
return GetJSPrivateSafeish<WorkerGlobalScope>(aCx, aObj); return GetJSPrivateSafeish<WorkerGlobalScope>(aCx, aObj);
} }
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
sClass.name, aFunctionName, sClass.name, aFunctionName, classPtr->name);
classPtr ? classPtr->name : "object");
return NULL; return NULL;
} }

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

@ -148,20 +148,14 @@ private:
static XMLHttpRequestUpload* static XMLHttpRequestUpload*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL;
if (aObj) {
XMLHttpRequestUpload* priv = GetPrivate(aCx, aObj); XMLHttpRequestUpload* priv = GetPrivate(aCx, aObj);
if (priv) { if (priv) {
return priv; return priv;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); JS_GET_CLASS(aCx, aObj)->name);
return NULL; return NULL;
} }
@ -373,20 +367,14 @@ private:
static XMLHttpRequestPrivate* static XMLHttpRequestPrivate*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName) GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{ {
JSClass* classPtr = NULL;
if (aObj) {
XMLHttpRequestPrivate* priv = GetPrivate(aCx, aObj); XMLHttpRequestPrivate* priv = GetPrivate(aCx, aObj);
if (priv) { if (priv) {
return priv; return priv;
} }
classPtr = JS_GET_CLASS(aCx, aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName, JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
classPtr ? classPtr->name : "object"); JS_GET_CLASS(aCx, aObj)->name);
return NULL; return NULL;
} }