Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8233747: JVM crash in com.sun.webkit.dom.DocumentImpl.createAttribute #47

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,7 +27,9 @@

#include <jni.h>

#include <wtf/Ref.h>
#include <wtf/RefPtr.h>
#include <wtf/GetPtr.h>
#include <wtf/text/WTFString.h>
#include "ExceptionOr.h"

Expand Down Expand Up @@ -58,6 +60,8 @@ void raiseNotSupportedErrorException(JNIEnv*);
void raiseDOMErrorException(JNIEnv*, Exception&&);

template<typename T> T raiseOnDOMError(JNIEnv*, ExceptionOr<T>&&);
template<typename T> T* raiseOnDOMError(JNIEnv*, ExceptionOr<Ref<T>>&&);
String raiseOnDOMError(JNIEnv*, ExceptionOr<String>&&);
void raiseOnDOMError(JNIEnv*, ExceptionOr<void>&&);

inline void raiseOnDOMError(JNIEnv* env, ExceptionOr<void>&& possibleException)
Expand All @@ -66,10 +70,30 @@ inline void raiseOnDOMError(JNIEnv* env, ExceptionOr<void>&& possibleException)
raiseDOMErrorException(env, possibleException.releaseException());
}

inline String raiseOnDOMError(JNIEnv* env, ExceptionOr<String>&& exceptionOrReturnValue)
{
if (exceptionOrReturnValue.hasException()) {
raiseDOMErrorException(env, exceptionOrReturnValue.releaseException());
return emptyString();
}
return exceptionOrReturnValue.releaseReturnValue();
}

template<typename T> inline T* raiseOnDOMError(JNIEnv* env, ExceptionOr<Ref<T>>&& exceptionOrReturnValue)
{
if (exceptionOrReturnValue.hasException()) {
raiseDOMErrorException(env, exceptionOrReturnValue.releaseException());
return nullptr;
}
return WTF::getPtr(exceptionOrReturnValue.releaseReturnValue());
}

template<typename T> inline T raiseOnDOMError(JNIEnv* env, ExceptionOr<T>&& exceptionOrReturnValue)
{
if (exceptionOrReturnValue.hasException())
if (exceptionOrReturnValue.hasException()) {
raiseDOMErrorException(env, exceptionOrReturnValue.releaseException());
return static_cast<T>(NULL);
}
return exceptionOrReturnValue.releaseReturnValue();
}

Expand Down
Expand Up @@ -417,6 +417,26 @@ public void handleEvent(Event evt) {
});
}

// JDK-8233747
@Test public void testCreateAttribute() {
final Document doc = getDocumentFor("src/test/resources/test/html/dom.html");
submit(() -> {
try {
//invalid attribute
Attr attr = doc.createAttribute(":/test");
fail("DOMException expected but not thrown");
} catch (DOMException ex) {
// Expected.
} catch (Throwable ex) {
fail("DOMException expected but instead threw " + ex.getClass().getName());
}

String attributeName = "test";
Attr attr = doc.createAttribute(attributeName);
assertEquals("Created attribute", attributeName, attr.getName());
});
}

// helper methods

private void verifyChildRemoved(Node parent,
Expand Down