Skip to content

Commit

Permalink
Merge pull request #1150 from openkraken/fix/document-location
Browse files Browse the repository at this point in the history
fix: document location
  • Loading branch information
wssgcg1213 committed Feb 9, 2022
2 parents 0575e69 + 2fdc45a commit 1793d90
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bridge/bindings/qjs/bom/window_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,18 @@ window.postMessage({
bridge->evaluateScript(code.c_str(), code.size(), "vm://", 0);
EXPECT_EQ(logCalled, true);
}

TEST(Window, location) {
auto bridge = TEST_init();
static bool logCalled = false;
kraken::KrakenPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
logCalled = true;
EXPECT_STREQ(message.c_str(), "true true");
};

std::string code = std::string(R"(
console.log(window.location !== undefined, window.location === document.location);
)");
bridge->evaluateScript(code.c_str(), code.size(), "vm://", 0);
EXPECT_EQ(logCalled, true);
}
5 changes: 5 additions & 0 deletions bridge/bindings/qjs/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ bool Document::isCustomElement(const std::string& tagName) {
return elementConstructorMap.count(tagName) > 0;
}

IMPL_PROPERTY_GETTER(Document, location)(JSContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* document = static_cast<DocumentInstance*>(JS_GetOpaque(this_val, Document::classId()));
return JS_GetPropertyStr(ctx, document->m_context->global(), "location");
}

IMPL_PROPERTY_GETTER(Document, nodeName)(JSContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NewString(ctx, "#document");
}
Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/dom/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Document : public Node {
private:
DEFINE_PROTOTYPE_READONLY_PROPERTY(nodeName);
DEFINE_PROTOTYPE_READONLY_PROPERTY(all);
DEFINE_PROTOTYPE_READONLY_PROPERTY(location);
DEFINE_PROTOTYPE_READONLY_PROPERTY(documentElement);
DEFINE_PROTOTYPE_READONLY_PROPERTY(children);
DEFINE_PROTOTYPE_READONLY_PROPERTY(head);
Expand Down

0 comments on commit 1793d90

Please sign in to comment.