Skip to content

Commit f1108b0

Browse files
arun-josephkevinrushforth
authored andcommitted
8233747: JVM crash in com.sun.webkit.dom.DocumentImpl.createAttribute
Reviewed-by: kcr, ghb
1 parent 3c4d68d commit f1108b0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

modules/javafx.web/src/main/native/Source/WebCore/bindings/java/JavaDOMUtils.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
#include <jni.h>
2929

30+
#include <wtf/Ref.h>
3031
#include <wtf/RefPtr.h>
32+
#include <wtf/GetPtr.h>
3133
#include <wtf/text/WTFString.h>
3234
#include "ExceptionOr.h"
3335

@@ -58,6 +60,8 @@ void raiseNotSupportedErrorException(JNIEnv*);
5860
void raiseDOMErrorException(JNIEnv*, Exception&&);
5961

6062
template<typename T> T raiseOnDOMError(JNIEnv*, ExceptionOr<T>&&);
63+
template<typename T> T* raiseOnDOMError(JNIEnv*, ExceptionOr<Ref<T>>&&);
64+
String raiseOnDOMError(JNIEnv*, ExceptionOr<String>&&);
6165
void raiseOnDOMError(JNIEnv*, ExceptionOr<void>&&);
6266

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

73+
inline String raiseOnDOMError(JNIEnv* env, ExceptionOr<String>&& exceptionOrReturnValue)
74+
{
75+
if (exceptionOrReturnValue.hasException()) {
76+
raiseDOMErrorException(env, exceptionOrReturnValue.releaseException());
77+
return emptyString();
78+
}
79+
return exceptionOrReturnValue.releaseReturnValue();
80+
}
81+
82+
template<typename T> inline T* raiseOnDOMError(JNIEnv* env, ExceptionOr<Ref<T>>&& exceptionOrReturnValue)
83+
{
84+
if (exceptionOrReturnValue.hasException()) {
85+
raiseDOMErrorException(env, exceptionOrReturnValue.releaseException());
86+
return nullptr;
87+
}
88+
return WTF::getPtr(exceptionOrReturnValue.releaseReturnValue());
89+
}
90+
6991
template<typename T> inline T raiseOnDOMError(JNIEnv* env, ExceptionOr<T>&& exceptionOrReturnValue)
7092
{
71-
if (exceptionOrReturnValue.hasException())
93+
if (exceptionOrReturnValue.hasException()) {
7294
raiseDOMErrorException(env, exceptionOrReturnValue.releaseException());
95+
return static_cast<T>(NULL);
96+
}
7397
return exceptionOrReturnValue.releaseReturnValue();
7498
}
7599

modules/javafx.web/src/test/java/test/javafx/scene/web/DOMTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,26 @@ public void handleEvent(Event evt) {
415415
});
416416
}
417417

418+
// JDK-8233747
419+
@Test public void testCreateAttribute() {
420+
final Document doc = getDocumentFor("src/test/resources/test/html/dom.html");
421+
submit(() -> {
422+
try {
423+
//invalid attribute
424+
Attr attr = doc.createAttribute(":/test");
425+
fail("DOMException expected but not thrown");
426+
} catch (DOMException ex) {
427+
// Expected.
428+
} catch (Throwable ex) {
429+
fail("DOMException expected but instead threw " + ex.getClass().getName());
430+
}
431+
432+
String attributeName = "test";
433+
Attr attr = doc.createAttribute(attributeName);
434+
assertEquals("Created attribute", attributeName, attr.getName());
435+
});
436+
}
437+
418438
// helper methods
419439

420440
private void verifyChildRemoved(Node parent,

0 commit comments

Comments
 (0)