Background:
When methods are attached on a map type like so:
type Foo map[string]string
func (f Foo) Bar() {
fmt.Printf("Hello World");
}
vm := otto.New();
vm.Set("foo", Foo{});
vm.Run(`
foo.Bar();
`);
You get:
Error in Run: TypeError: 'Bar' is not a function
The Fix:
I looked into how/why the same works for arrays. After
all array properties are tested (such as length, and any integer-based members),
the code then looks for any methods attached to that type.
This change literally copies that code over into
maps.
This is very useful when working with the http.Request object which
has the http.Header type that is a map[string][]string, with a lot
of useful methods attached to it.
Added unit test to support/guard the change (and map had no test before)
Responded to PR comments
An upstream change (http://golang.org/cl/30371) makes the Go encoder
to be more compliant with the ES6 standard. Ironically, this change
causes Test_issue80 to fail on the larger number ranges.
To make this test work on both Go 1.7 and Go 1.8, we delete the larger
value tests, which are arguably locking in the wrong behavior.
* add benchmarks and tests for native function calls
* improve conversion of various native function parameters
* add support for more types of native function parameters
* improve performance of most parameter types
* add stackFramesToPop argument to error factories
* put native functions in their own stack frames
* add tests for native stack frames
* amend Context functionality to account for native frames
This patch implements source map support in the parser, the runtime, the
script record, and the stack trace printing.
The library used to parse and use the source maps is gopkg.in/sourcemap.v1.
Unlike earlier versions of this patch, the consumer of otto does not need
parse the source map on their own - it's now handled similarly to parsing
JavaScript content.
To use a source map, the consumer must explicitly parse their source into
a `Script` object with `Otto.CompileWithSourceMap`. The script record
returned from that call will carry source map information with it, and
all location-related functions should reflect the original source
positions.