Enable the whitespace linter and fix the errors resulting from it.
Also:
* Remove unneeded golangci-lint config for disabled linters.
* Correct test number for panic in previous commit.
Value and Object now conform to the json.Marshaler interface and produce the
correct JSON when passed (directly or indirectly) to json.Marshal().
Before, both types would marshal as "{}" because they're structs with no public
fields.
This fixes some nasty problems marshaling object trees that mix Go and JS
collections. This can happen when you pass a Go collection into a JS function,
which modifies it adding JS values; and then back in Go you marshal the
collection to JSON. Before this commit the JS values would marshal to "{}".
(The new unit test TestNestedJSONMarshaling demonstrates this.)
Fixes#262
Disable new linters which aren't compatible with this code module.
Upgrade github actions to fix caching issues.
Run go mod to bring in new styling.
Remove space on nolint declarations.
Apply all changes to whitespace as required to pass goimports linter.
Only trigger checks on pull_request which works for pulls from other
forks, where as push only works from the same repo.
* 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.
This change adds a handful of functions to `otto.Otto` type that make
it easier to create proper `Error` values from native code. Previously,
the only way to do this was to call the error's constructor from
JavaScript like `vm.Call("TypeError", "message")`. `Call` can fail for
various reasons, and also modifies the current call stack.
These new functions can't fail, and since they don't involve any
JavaScript execution, won't modify the call stack. The new functions
are:
* `MakeCustomError(name, message string) Value`
* `MakeRangeError(message string) Value`
* `MakeSyntaxError(message string) Value`
* `MakeTypeError(message string) Value`
`MakeCustomError` creates an `Error` object with a specific `name` value.
The other functions cover some common error types, and call specific
functions in the runtime to construct errors with the correct prototypes.
If we need to implement any other error types, it'll mostly be copy/paste.
This change introduces a Context method to otto that allows developers to get
information about the current execution context. The method returns a Context
struct that contains information such as the filename, line and column of the
current execution, the current value of this, the stacktrace and the available
symbols at the current context.
Previously, it was a publically accessible but invalid value (valueEmpty).
* Deprecate internal use of UndefinedValue(), NullValue(), FalseValue(), TrueValue()
* Guard against Empty, Result, Reference values from escaping the package
* Streamline what we get from "otto/parser"
* Get rid of some "otto/parser" cruft
* FunctionExpression => FunctionLiteral
* The debugger statement (debugger) should do nothing (not panic)
* Fix aspects of function expression call evaluation
* Faster, more straightforward, etc.
* More advanced object literals (get ..., set ...)
* More tests using JavaScript from the wild (http://cdnjs.com/)