Skip to content
Permalink
Browse files

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

Reviewed-by: kcr, ghb
  • Loading branch information
arun-Joseph authored and kevinrushforth committed Jan 6, 2020
1 parent 3c4d68d commit f1108b0ae507dadf407b9971e54b40a84c1b853f
@@ -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"

@@ -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)
@@ -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();
}

@@ -415,6 +415,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,

0 comments on commit f1108b0

Please sign in to comment.
You can’t perform that action at this time.