-
Notifications
You must be signed in to change notification settings - Fork 0
Add strict browser wrappers for window timers and navigator share #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e833f1b
JS-47 Add strict window timers and navigator share wrappers
sbsoftware-agent f41ab41
JS-47 Forward browser unknown methods to window wrappers
sbsoftware-agent 8157118
JS-47 Support NamedTuple args in context call-chain builder
sbsoftware-agent 859abd9
JS-47 Simplify context argument serialization
sbsoftware-agent a0e8bea
JS-47 Move window member lookups into Window wrapper
sbsoftware-agent fcf1e08
JS-47 Let compiler resolve browser method forwarding
sbsoftware-agent 773c568
JS-47 Remove extra browser context wrapper unit tests
sbsoftware-agent aae7c36
JS-47 Drop window member placeholders from strict validation
sbsoftware-agent 7cb1f74
JS-47 Remove strict-mode wrapper pre-check introspection
sbsoftware-agent 40f6267
JS-47 Remove strict pre-probing and tighten literal_js guard
sbsoftware-agent c7e9a07
JS-47 Nest strict-mode guard for literal_js handling
sbsoftware-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| require "../../spec_helper" | ||
|
|
||
| module JS::Context::BrowserAPISpec | ||
| class StrictWindowTimersCode < JS::Code | ||
| def_to_js strict: true do | ||
| timer = window.setTimeout(-> { | ||
| console.log("tick") | ||
| }, 1000) | ||
| window.clearTimeout(timer) | ||
| end | ||
| end | ||
|
|
||
| class StrictNavigatorShareCode < JS::Code | ||
| def_to_js strict: true do | ||
| navigator.share(text: "Done", title: "Status", url: "https://example.com") | ||
| end | ||
| end | ||
|
|
||
| class StrictReceiverlessWindowTimersCode < JS::Code | ||
| def_to_js strict: true do | ||
| timer = setTimeout(-> { | ||
| console.log("tick") | ||
| }, 1000) | ||
| clearTimeout(timer) | ||
| end | ||
| end | ||
|
|
||
| describe "strict browser context timer calls" do | ||
| it "transpiles window.setTimeout and window.clearTimeout in strict mode" do | ||
| expected = <<-JS.squish | ||
| var timer; | ||
| timer = window.setTimeout(() => { | ||
| console.log("tick"); | ||
| }, 1000); | ||
| window.clearTimeout(timer); | ||
| JS | ||
|
|
||
| StrictWindowTimersCode.to_js.should eq(expected) | ||
| end | ||
| end | ||
|
|
||
| describe "strict browser context forwarded window calls" do | ||
| it "transpiles receiverless timer calls by forwarding through window" do | ||
| expected = <<-JS.squish | ||
| var timer; | ||
| timer = setTimeout(() => { | ||
| console.log("tick"); | ||
| }, 1000); | ||
| clearTimeout(timer); | ||
| JS | ||
|
|
||
| StrictReceiverlessWindowTimersCode.to_js.should eq(expected) | ||
| end | ||
| end | ||
|
|
||
| describe "strict browser context navigator calls" do | ||
| it "transpiles navigator.share with named args in strict mode" do | ||
| expected = <<-JS.squish | ||
| navigator.share({text: "Done", title: "Status", url: "https://example.com"}); | ||
| JS | ||
|
|
||
| StrictNavigatorShareCode.to_js.should eq(expected) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| require "./context_object" | ||
| require "./undefined" | ||
|
|
||
| module JS | ||
| module Context | ||
| class Navigator < JS::Context::ContextObject | ||
| def initialize | ||
| super("navigator") | ||
| end | ||
|
|
||
| def share(*, text : String, title : String? = nil, url : String? = nil) : JS::Context::Undefined | ||
| # Omit nil keys so we emit a realistic Web Share payload object. | ||
| payload = if title && url | ||
| {text: text, title: title, url: url} | ||
| elsif title | ||
| {text: text, title: title} | ||
| elsif url | ||
| {text: text, url: url} | ||
| else | ||
| {text: text} | ||
| end | ||
| JS::Context::Undefined.new(to_js_ref, "share", payload) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| require "./context_object" | ||
|
|
||
| module JS | ||
| module Context | ||
| class TimerHandle < JS::Context::ContextObject | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| require "./context_object" | ||
| require "./timer_handle" | ||
| require "./undefined" | ||
|
|
||
| module JS | ||
| module Context | ||
| alias TimerDelay = Int::Primitive | Float32 | Float64 | ||
| alias TimerCallback = String | JS::Context::ContextObject | ||
|
|
||
| class Window < JS::Context::ContextObject | ||
| def initialize | ||
| super("window") | ||
| end | ||
|
|
||
| def setTimeout(callback : JS::Context::TimerCallback, delay : JS::Context::TimerDelay) : JS::Context::TimerHandle | ||
| JS::Context::TimerHandle.new(to_js_ref, "setTimeout", callback, delay) | ||
| end | ||
|
|
||
| def clearTimeout(handle : JS::Context::TimerHandle) : JS::Context::Undefined | ||
| JS::Context::Undefined.new(to_js_ref, "clearTimeout", handle) | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.