Skip to content

Commit

Permalink
Merge pull request #58 from jessedoyle/runtime-call-noargs
Browse files Browse the repository at this point in the history
fix(runtime): function call with no arguments
  • Loading branch information
jessedoyle authored Mar 4, 2020
2 parents f0e0420 + 2899685 commit a5335f3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.19.1 - March 3, 2020

- **Bugfix**: Call function properties when using `Duktape::Runtime#call` with no function arguments. [PR 58](https://github.com/jessedoyle/duktape.cr/pull/58), [Issue 57](https://github.com/jessedoyle/duktape.cr/issues/57). Thanks @dinh for reporting!

# v0.19.0 - Jan 17, 2020

- Update Duktape version to `2.5.0`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ version: 1.0.0 # your project's version
dependencies:
duktape:
github: jessedoyle/duktape.cr
version: ~> 0.19.0
version: ~> 0.19.1
```
then execute:
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: duktape
version: 0.19.0
version: 0.19.1

authors:
- Jesse Doyle <jdoyle@ualberta.ca>
Expand Down
20 changes: 20 additions & 0 deletions spec/duktape/runtime_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@ describe Duktape::Runtime do
rt.ctx.get_top.should eq(0)
end
end

context "fix: https://github.com/jessedoyle/duktape.cr/issues/57", tags: "bugfix" do
it "calls functions when no arguments are provided" do
rt = Duktape::Runtime.new do |sbx|
sbx.eval! <<-JS
var called = false
function test() {
called = true;
return called;
}
JS
end

rt.call("test")
result = rt.call("called")

result.should be_true
end
end
end

describe "eval" do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/expectations/js_type_expectation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Spec
end

def failure_message(actual_value)
"expected #{@target.inspect}\, got #{Duktape::TYPES[actual_value].inspect}"
"expected #{@target.inspect}, got #{Duktape::TYPES[actual_value].inspect}"
end

def negative_failure_message(actual_value)
Expand Down
15 changes: 6 additions & 9 deletions src/duktape/runtime.cr
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,14 @@ module Duktape

# :nodoc:
private def perform_call(args)
push_args(args)

obj_idx = -(args.size + 2)
if args.size > 0
push_args args
# We want a reference to the last property that was
# successfully accessed via `get_prop`. Because we
# leave the last property name in the chain as a string
# , this should only depend on the number of arguments
# on the stack.
obj_idx = -(args.size + 2)
@context.call_prop obj_idx, args.size
@context.call_prop(obj_idx, args.size)
else
@context.get_prop -2
@context.get_prop(obj_idx)
@context.call(0) if @context.is_callable(-1)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/duktape/version.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Duktape
module VERSION
MAJOR = 0
MINOR = 19
TINY = 0
TINY = 1
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join "."
Expand Down

0 comments on commit a5335f3

Please sign in to comment.