Skip to content

Commit

Permalink
Merge pull request #733 from openkraken/fix/modify_innerHTML_getproperty
Browse files Browse the repository at this point in the history
fix: innerHTML of getProperty should get String of children.
  • Loading branch information
answershuto authored Oct 18, 2021
2 parents cb6d4d3 + da5d4b1 commit a4df354
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion bridge/bindings/jsc/DOM/element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ JSValueRef ElementInstance::getProperty(std::string &name, JSValueRef *exception
return JSObjectMakeArray(_hostClass->ctx, arguments.size(), arguments.data(), nullptr);
}
case JSElement::ElementProperty::innerHTML: {
return JSValueMakeString(ctx, JSStringCreateWithUTF8CString(toString().c_str()));
std::string s = "";
for (auto child: childNodes) {
s += static_cast<ElementInstance *>(child)->toString();
}
return JSValueMakeString(ctx, JSStringCreateWithUTF8CString(s.c_str()));
}
}

Expand Down
6 changes: 3 additions & 3 deletions integration_tests/specs/dom/innerHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('innerHTML', () => {

document.body.appendChild(div);

expect(div.innerHTML).toEqual('<div style="height: 100px;width: 100px;"></div>');
expect(document.body.innerHTML).toEqual('<div style="height: 100px;width: 100px;"></div>');
});

it('should work width attribute when get property', async () => {
Expand All @@ -31,7 +31,7 @@ describe('innerHTML', () => {

document.body.appendChild(div);

expect(div.innerHTML).toEqual('<div attr-key="attr-value" ></div>');
expect(document.body.innerHTML).toEqual('<div attr-key="attr-value" ></div>');
});

it('should work width attribute when get property', async () => {
Expand All @@ -40,7 +40,7 @@ describe('innerHTML', () => {

document.body.appendChild(div);

expect(div.innerHTML).toEqual('<div attr-key="attr-value" ></div>');
expect(document.body.innerHTML).toEqual('<div attr-key="attr-value" ></div>');
});

it('set empty string should remove all children', async () => {
Expand Down

0 comments on commit a4df354

Please sign in to comment.