Skip to content

Commit 09ccc57

Browse files
authored
Merge pull request #70 from openkraken/fix/insert_before_crash
fix: fix insertBefore crash when passing none node object.
2 parents a3ffee7 + 6e6d79c commit 09ccc57

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

bridge/bindings/jsc/DOM/node.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ JSValueRef JSNode::appendChild(JSContextRef ctx, JSObjectRef function, JSObjectR
240240
JSObjectRef nodeObjectRef = JSValueToObject(ctx, nodeValueRef, exception);
241241
auto nodeInstance = static_cast<NodeInstance *>(JSObjectGetPrivate(nodeObjectRef));
242242

243-
if (nodeInstance == nullptr || nodeInstance->_identify != NODE_IDENTIFY) {
243+
if (nodeInstance == nullptr || nodeInstance->document != selfInstance->document) {
244244
throwJSError(ctx, "Failed to execute 'appendChild' on 'Node': first arguments should be an Node type.", exception);
245245
return nullptr;
246246
}
@@ -288,7 +288,7 @@ JSValueRef JSNode::insertBefore(JSContextRef ctx, JSObjectRef function, JSObject
288288
auto selfInstance = static_cast<NodeInstance *>(JSObjectGetPrivate(thisObject));
289289
auto nodeInstance = static_cast<NodeInstance *>(JSObjectGetPrivate(nodeObjectRef));
290290

291-
if (nodeInstance == nullptr || nodeInstance->_identify != NODE_IDENTIFY) {
291+
if (nodeInstance == nullptr || nodeInstance->document != selfInstance->document) {
292292
throwJSError(ctx, "Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'", exception);
293293
return nullptr;
294294
}
@@ -331,14 +331,14 @@ JSValueRef JSNode::replaceChild(JSContextRef ctx, JSObjectRef function, JSObject
331331
auto oldChildInstance = static_cast<NodeInstance *>(JSObjectGetPrivate(oldChildObjectRef));
332332

333333
if (oldChildInstance == nullptr || oldChildInstance->parentNode != selfInstance ||
334-
oldChildInstance->_identify != NODE_IDENTIFY) {
334+
oldChildInstance->document != selfInstance->document) {
335335
throwJSError(ctx,
336336
"Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.",
337337
exception);
338338
return nullptr;
339339
}
340340

341-
if (newChildInstance == nullptr || newChildInstance->_identify != NODE_IDENTIFY) {
341+
if (newChildInstance == nullptr || newChildInstance->document != selfInstance->document) {
342342
throwJSError(ctx, "Failed to execute 'replaceChild' on 'Node': The new node is not a type of node.", exception);
343343
return nullptr;
344344
}
@@ -424,7 +424,7 @@ JSValueRef JSNode::removeChild(JSContextRef ctx, JSObjectRef function, JSObjectR
424424
auto selfInstance = static_cast<NodeInstance *>(JSObjectGetPrivate(thisObject));
425425
auto nodeInstance = static_cast<NodeInstance *>(JSObjectGetPrivate(nodeObjectRef));
426426

427-
if (nodeInstance == nullptr || nodeInstance->_identify != NODE_IDENTIFY) {
427+
if (nodeInstance == nullptr || nodeInstance->document != selfInstance->document) {
428428
throwJSError(ctx, "Failed to execute 'removeChild' on 'Node': 1st arguments is not a Node object.", exception);
429429
return nullptr;
430430
}

bridge/include/kraken_bridge_jsc.h

-3
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,6 @@ enum NodeType {
487487
DOCUMENT_FRAGMENT_NODE = 11
488488
};
489489

490-
#define NODE_IDENTIFY 1
491-
492490
class JSNode : public JSEventTarget {
493491
public:
494492
static std::unordered_map<JSContext *, JSNode *> instanceMap;
@@ -575,7 +573,6 @@ class NodeInstance : public EventTargetInstance {
575573
void unrefer();
576574

577575
int32_t _referenceCount{0};
578-
int32_t _identify{NODE_IDENTIFY};
579576

580577
DocumentInstance *document{nullptr};
581578
virtual void _notifyNodeRemoved(NodeInstance *node);

0 commit comments

Comments
 (0)