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

58 Commits

Author SHA1 Message Date
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
Robert Krimen
ea621687a4 Add Otto.Copy() 2013-07-14 14:20:01 -07:00
Robert Krimen
4ebf6416d0 Fix Uint32 Array/String indexing
Also, a bunch of toValue_* streamlining
And maybe a few miscellaneous tweaks
2013-06-22 15:49:22 +02:00
Robert Krimen
73bf2f9fa8 Implement return/break/continue without panic/recover
This fixes #25
2013-06-13 22:17:04 -07:00
Robert Krimen
c55510cb36 Inline context initialization & improve _object.value
* Context setup is now done via _newContext.
* _newContext is a function that resides in inline.go. _newContext is very flat,
resulting in almost no function calls (a 180 from the earlier status quo).
* inline.go is a Go source file that is built by Perl (via inline).
* Lots of crufty functions removed (along with all of their TODO & FIXME).
* In addition, before, the underlying value of _object.value was a pointer to
something. This made for extra work, since the type of _object.value is interface{},
which is already something of a pointer. Now, the underlying value of _object.value
in Function, Date, RegExp, ..., is a struct value.
* type_function.go was streamlined, removing superfluous struct fields and methods.
* There is now less "digging" to get to the actual value of a function, which is important
when makings lots of calls.

Before (without inline):

    PASS
    BenchmarkNew        2000           1067871 ns/op
    ok      github.com/robertkrimen/otto    3.336s
    PASS
    BenchmarkNew        2000           1077644 ns/op
    ok      github.com/robertkrimen/otto    3.367s

After (with inline):

    PASS
    BenchmarkNew       10000            364418 ns/op
    ok      github.com/robertkrimen/otto    4.616s
    PASS
    BenchmarkNew       10000            307241 ns/op
    ok      github.com/robertkrimen/otto    4.051s

This (partially) fixes #22
2013-06-09 18:28:18 -07:00
Robert Krimen
04ea4a2729 Prevent otto.Value from becoming a _goStructObject
Fix #21, this would happen during .Set(...)
2013-06-05 21:52:59 -07:00
Robert Krimen
3c8bf4f87c Fix Arguments initialization
Should contain what was passed, not exactly what was declared
2013-06-02 16:25:17 -07:00
Robert Krimen
6669f98a8e Improve type_go_* behavior 2013-05-31 22:50:51 -07:00
Robert Krimen
64182c96bd Handle Ptr properly in type_go_*
Though I'm not sure that &map..., or &[]..., makes sense.
2013-05-30 19:17:57 -07:00
Robert Krimen
e2e79bb697 A Value panic during a FunctionCall is the same as a throw in JavaScript 2013-05-19 15:54:10 -07:00
Robert Krimen
791a2c0c8e Add FunctionCall.Otto 2013-05-19 14:57:01 -07:00
Robert Krimen
699232d49a Consolidate run/runSafe into _runtime 2013-05-18 16:18:17 -07:00
Robert Krimen
7e2b4f2063 Rewrite of property handling to be more robust and compliant
* No more _stash
* Now using a "virtual table" system via _objectClass
* Make Array.concat GoArray compatible (via .isArray())

Fix #16
2013-05-12 14:14:51 -07:00
Robert Krimen
cfd5635e46 Fix iterator evaluation to return the proper result if a break happens 2013-04-27 22:03:12 +02:00
Robert Krimen
8ab608b974 Makefile for building of otto/otto*
Fix stray dbg(...) in runtime
2013-04-26 09:27:49 +02:00
Robert Krimen
2277e46d05 tryEvaluate => tryCatchEvaluate 2013-04-20 22:13:19 -07:00
Robert Krimen
345c4705f9 Improve function declaration: adhere more closely to the specification 2013-04-17 16:13:19 -07:00
Robert Krimen
260b2a48bf Fix (band-aid) Go/JavaScript cross-boundary error transformation 2013-03-06 12:07:26 -08:00
Robert Krimen
d1c4cf79ab Fix always passing in the global object as this for eval
Should be passing in the this of the parent execution context instead
2013-03-05 14:41:50 -08:00
Robert Krimen
299495ba0a Set callee property of Arguments object 2013-03-05 09:08:46 -08:00
Robert Krimen
d68cd0afe2 Establish eval execution context with the global object 2013-02-27 21:42:30 -08:00
Robert Krimen
16a30ee951 Differentiate between direct and indirect eval 2013-02-27 21:23:21 -08:00
Robert Krimen
fc55f7c7d9 Remove cruft from arguments 2013-02-25 13:34:37 -08:00
Robert Krimen
c5f05dd873 Rework _reference interface to correspond to ECMA more closely 2013-02-25 13:26:12 -08:00
Robert Krimen
03cd7ef8f7 Functions declared in a function should replace parameters 2013-02-24 14:28:16 -08:00
Robert Krimen
321cc0dca8 Add _argumentsStash, with better conforming arguments behavior:
1. Can not delete a function parameter
    2. Deleting the index of an arguments object simply
       removes the link to that function parameter
2013-02-24 14:28:07 -08:00
Robert Krimen
a879744c20 Add Go <=> JavaScript type interaction
Via reflection for struct, map, and slice/array
Fix #10
2013-02-04 10:31:44 -08:00
Robert Krimen
20d2e8bba6 gofmt
Ugh.
2013-01-25 09:59:42 -08:00