1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
Commit Graph

85 Commits

Author SHA1 Message Date
Steven Hartland
3697ad1504
fix: stack panic truncation (#465)
Fix stack being truncated due to double conversion to _error.

Fixes #329
2022-11-28 14:07:27 +00:00
Steven Hartland
c4b94300e3
feat: support push to go slices (#460)
Add support for direct use of push to go slices without converting to
array using .slice().

Fixes #357

Also:
* Add classGoSlice and use it, to make it clear the type when debugging.
2022-11-27 23:09:00 +00:00
Steven Hartland
52d4954a54
fix: catch panic in try catch (#455)
Ensure that a panic is caught if thrown in a try catch block.

Fixes #382
2022-11-26 11:35:10 +00:00
Steven Hartland
08e7a8d472
fix: array writes (#454)
Fix array writes not being persisted by passing in writeable
reflect.Value when available instead of .Interface() which looses that
property.

Also:
* Use value.IsValid() instead of comparison with zero entry.
* Use propertyLength instead of literal.

Fixes #386
2022-11-26 02:57:29 +00:00
Steven Hartland
041379fef3
fix: field pointers in fieldIndexByName (#452)
Allow pointers to structs in fieldIndexByName.

Also:
* Use reflect.Type.Elem() vs reflect.ValueOf(t).Elem().Type().
* Format bug_test.go to fix lint failure.
2022-11-25 22:13:15 +00:00
Alessandro Rinaldi
37f2928676
fix: support struct pointers (#370)
Fix panic when handling a pointer to a struct.

Fixes #369
2022-11-25 21:48:16 +00:00
Steven Hartland
e311ec4305
fix: field index on interface (#449)
Don't look on interface types for field names, as it causes a
panic.

Fixes #390
2022-11-25 18:40:32 +00:00
Steven Hartland
8d2eaa7768
test: add test for issue #186 (#419)
Add a test which exercises issue #186

Also:
* Quote types in "can't convert from %q to %q" errors.
2021-09-27 21:35:16 +01:00
Steven Hartland
9297a9abe4
feat: add github action tests and linting (#418)
Leverage github actions for tests and linting.

This includes fixing a bunch of issues highlighted by golangci
including:
* Dead code.
* Ineffectual assigns.
* Goto warnings.
* Nil return err.
* Reused literal strings.
* Test parameter order.

Also:
* Setup clog.
2021-09-27 16:19:28 +01:00
Conrad Pankoff
ef014fd054 improve error messages when converting values 2020-09-23 08:17:31 +10:00
Conrad Pankoff
9fa7c0c0f8 support converting to json.RawMessage 2019-12-15 13:36:24 +11:00
Conrad Pankoff
3ef5863438 allow conversion from [u]int* to float 2019-12-15 13:18:22 +11:00
Conrad Pankoff
0f57984957 use consistent field access rules across read/write and argument conversion 2019-12-15 13:18:22 +11:00
deoxxa
03d472dc43 extend convertCallParameter passthrough behaviour to _goArrayObject 2018-05-06 18:43:58 +10:00
deoxxa
e335b9a887 implement TextUnmarshaller function parameter conversion 2018-05-06 18:12:42 +10:00
deoxxa
09c2169283 implement and test basic [object Object] -> struct conversion 2018-05-06 17:43:12 +10:00
deoxxa
e177400a34 fix a bug related to converting Value objects to specific interfaces 2018-05-06 14:28:05 +10:00
Vincent Vanackere
21ec96599b Fix bug in runtime when exporting null|undefined to interface{} (#244) 2017-04-24 11:46:44 +01:00
jan-karl
ea095c6386 fix for casting GoArrays on in convertCallParameter 2016-10-01 02:31:40 -04:00
deoxxa
9597787793 fix calling go functions with goStructObject arguments 2016-05-30 13:30:33 +10:00
deoxxa
ccf93984d9 implement configurable stack trace limit 2016-05-08 18:13:57 +10:00
deoxxa
1fe0007dcb refactor native function parameter conversion
* 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
2016-05-07 21:35:17 +10:00
deoxxa
668c95f04e make call stacks aware of native functions
* 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
2016-05-07 20:55:09 +10:00
deoxxa
bd5fb254e3 add source map support
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.
2016-05-02 19:34:04 +10:00
deoxxa
8e3ecbc5e3 avoid scope depth check for first stack frame 2016-04-25 11:39:17 +10:00
deoxxa
014e1807a9 remove redundant unnecessary error prefix 2016-04-04 00:32:44 +10:00
deoxxa
c142472392 add simple stack depth limit mechanism 2016-04-04 00:07:41 +10:00
deoxxa
fd1eddd0f9 add support for an external Math.random() provider 2016-02-18 22:08:25 +11:00
Conrad Pankoff
4a7676e51c Merge pull request #142 from deoxxa/add-debugger-hook
add a way to trigger something with `debugger`
2015-12-05 21:14:00 +11:00
deoxxa
7f15b1724e add a way to trigger something with debugger 2015-12-05 19:25:33 +11:00
deoxxa
72211f7dbb add Eval() to execute code in the current vm scope 2015-12-05 19:05:21 +11:00
Steven Hartland
a30a6a7b53 Improve method call parameter processing
Add support for the final parameter to a variadic function to be a slice.

Add support for conversion of slice parameters.

Expand numeric conversion support to include all int and uint types as souce types. This allows the result of bitwise calculations (int32) to be passed in as parameters.
2015-02-19 11:45:35 +00:00
Robert Krimen
c2346f4ada Merge pull request #103 from multiplay/multi-return
Support go multiple return values as an array
2015-02-15 16:28:43 -08:00
Steven Hartland
c25bb49761 Automatic numeric parameter conversion
Javascript uses int64 (literals) and float64 (default) representations for numbers so to allow easy use of go funcs apply automatic conversion for function parameters where it is safe to do so.
2015-02-12 15:48:45 +00:00
Steven Hartland
81b01b9fac Support go multiple return values as an array
Add support for go funcs which return multiple values by returning them as an array.

In the future this can be used along side destructuring assignment to provide a nice way to deal with multiple value returns e.g.
[val, err] = MyGoFunc()
2015-02-12 15:10:58 +00:00
Robert Krimen
e6768252c2 Improve error reporting
* Delay entering global scope on code evaluation, not runtime creation

This fixes #66
2014-06-12 21:27:32 -07:00
Robert Krimen
f09ce5eac2 Add mutex locking for .Copy() 2014-05-30 20:27:30 -07:00
Robert Krimen
918abeb8d8 The zero value of Value is now defined to be undefined
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
2014-05-28 21:23:32 -07:00
Robert Krimen
9cd045ef04 Simplification & refactor of (parts of) the runtime
* Proper lowercasing for internal stuff
* *Environment => *_stash
* ExecutionContext => _scope
* Simpler & shallower call/construct mechanics
* Remove unnecessary fields & methods
* Better scoping (no more stack): []*_scope => _scope.outer
* Some speed improvements

In preparation for #66
2014-05-27 22:05:35 -07:00
Robert Krimen
ba678bc782 Use _runtime.toValue() instead of func toValue()
This fixes #72
2014-05-22 20:39:27 -07:00
Robert Krimen
bf7b16f4a3 Add internal compilation step
* 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
2014-04-19 14:05:51 -07:00
Robert Krimen
8aca2c886a Disable script marshalling/unmarshalling for now 2014-04-15 18:34:24 -07:00
Robert Krimen
ddca88af9b Add compilation (Script, vm.Compile, etc.) 2014-04-13 15:04:32 -07:00
Robert Krimen
f04cfab02d Add ability to parse []byte, *bytes.Buffer, io.Reader 2014-04-11 18:07:57 -07:00
Robert Krimen
ad8a97c028 New parser
* Faster, more straightforward, etc.
* More advanced object literals (get ..., set ...)
* More tests using JavaScript from the wild (http://cdnjs.com/)
2014-04-10 20:42:25 -07:00
Daniel Cannon
07737f86b9 Add ability to call struct methods
This fixes #60

This is incompatible with go 1.0.3
2014-03-16 09:04:00 -07:00
Daniel Cannon
661a61c5a0 Fix toValue not properly converting type aliases
This fixes #61
2014-03-16 08:46:20 -07:00
Robert Krimen
aef9bfcb9a Fix "memory leak" by gelcapping panic values with _exception
Basically, the Go runtime sees the gelcap shell of the exception,
which dissolves (payload is set to nil) once we catch the error.

This prevents the Go runtime from hanging onto a heavy object for the
panic log (or whatever it is doing with the panic value).

This fixes #59
2014-02-21 18:24:07 -08:00
Tim Jurcka
5fe23327c9 Add JSON
This closes #37, #11
2014-02-01 11:32:21 -08:00
Robert Krimen
aede245ed6 Include property names when inlining 2013-07-20 15:24:56 -07:00