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; Event* priv = GetPrivate(aCx, aObj);
if (priv) {
if (aObj) { return priv;
Event* priv = GetPrivate(aCx, aObj);
if (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. if (IsThisClass(classPtr)) {
JSClass* classPtr = NULL; return GetJSPrivateSafeish<MessageEvent>(aCx, aObj);
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (IsThisClass(classPtr)) {
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. if (IsThisClass(classPtr)) {
JSClass* classPtr = NULL; return GetJSPrivateSafeish<ErrorEvent>(aCx, aObj);
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (IsThisClass(classPtr)) {
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 (classPtr == &sClass) {
if (aObj) { return GetJSPrivateSafeish<ProgressEvent>(aCx, aObj);
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass) {
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; nsIDOMBlob* blob = GetPrivate(aCx, aObj);
if (blob) {
if (aObj) { return blob;
nsIDOMBlob* blob = GetPrivate(aCx, aObj);
if (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; nsIDOMFile* file = GetPrivate(aCx, aObj);
if (file) {
if (aObj) { return file;
nsIDOMFile* file = GetPrivate(aCx, aObj);
if (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; FileReaderSyncPrivate* fileReader = GetPrivate(aCx, aObj);
if (fileReader) {
if (aObj) { return fileReader;
FileReaderSyncPrivate* fileReader = GetPrivate(aCx, aObj);
if (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 (classPtr == &sClass || classPtr == ChromeWorker::Class()) {
if (aObj) { return GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass || classPtr == ChromeWorker::Class()) {
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. if (classPtr == &sClass) {
JSClass* classPtr = NULL; return GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aCx, aObj);
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass) {
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; return GetJSPrivateSafeish<WorkerGlobalScope>(aCx, aObj);
if (aObj) {
classPtr = JS_GET_CLASS(aCx, aObj);
if (classPtr == &sClass ||
classPtr == DedicatedWorkerGlobalScope::Class()) {
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; XMLHttpRequestUpload* priv = GetPrivate(aCx, aObj);
if (priv) {
if (aObj) { return priv;
XMLHttpRequestUpload* priv = GetPrivate(aCx, aObj);
if (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; XMLHttpRequestPrivate* priv = GetPrivate(aCx, aObj);
if (priv) {
if (aObj) { return priv;
XMLHttpRequestPrivate* priv = GetPrivate(aCx, aObj);
if (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;
} }