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

41 Commits

Author SHA1 Message Date
Steven Hartland
526e6b2be2 Merge pull request #106 from multiplay/float-precision
Prevent loss of float precision
2015-12-01 13:13:51 +00:00
Steven Hartland
e378501ad1 Merge pull request #108 from multiplay/array-types
Export arrays to common type if possible
2015-12-01 13:13:00 +00:00
Robert Krimen
7597815bd0 Fix toReflectValue(0) => float32
This fixes #123
2015-05-07 22:53:02 -07:00
Steven Hartland
abcc601db6 Prevent loss of float precision
When automatically converting a float to int type ensure we don't loose any precision.
2015-02-19 11:33:21 +00:00
Steven Hartland
72d92c8e19 Export arrays to common type if possible
If there is a common type for all values in an array export to a slice of that type otherwise return a slice of interfaces.
2015-02-17 23:18:23 +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
709a0aa7ff Value.string(), .float64(), .bool(), etc. 2014-06-06 21:29:40 -07:00
Robert Krimen
b813fe3676 Fix JSON.stringify treating large integers as float64
This fixes #80
2014-06-06 21:08:59 -07:00
Robert Krimen
6c7c425424 Fix toReflectValue to handle Struct, Map, Slice, etc.
This fixes #79
2014-06-04 18:08:42 -07:00
Robert Krimen
98be5e74da go vet
This fixes #76

I cheated on some of these.
2014-05-28 21:46:08 -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
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
661a61c5a0 Fix toValue not properly converting type aliases
This fixes #61
2014-03-16 08:46:20 -07:00
Robert Krimen
41e5803a57 Fix Value.isArray => isArray 2014-02-01 11:09:14 -08:00
Robert Krimen
3ba06f003c Fix NaN/+0/-0 comparison in Array.prototype.indexOf 2014-01-24 21:20:22 -08:00
Robert Krimen
4c1bc5857b Fix documentation (nikai3d)
This fixes #45

The errors are manifest in the README, but this is automatically generated from the go documentation, so we have to fix them at the source
2014-01-19 10:52:14 -08:00
Daniel Cannon
fd6b047e2b Updated toValue to properly handle nil pointers (dancannon)
Also, added test
2014-01-18 17:35:26 -08:00
Robert Krimen
091c371aea Change handling of undefined in .Export
This fixes #28
2013-06-22 16:33:41 +02: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
30e4c4b96d Fix .ToValue([]string{...}).Export() to return []string{...}
This fixes #24
2013-06-06 20:18:37 -07:00
Robert Krimen
7ff3e8668e Allow (internal) enumeration through _every_ Object property
For .freeze, .isFrozen, etc.
2013-06-02 15:21:25 -07:00
Robert Krimen
f745b98f2b Handle struct, map, & array/slice in exportNative 2013-05-30 18:57:33 -07:00
Robert Krimen
58eefe5c3d Handle toReflectValue of interface{}
Fix #19
2013-05-29 22:45:01 -07:00
Robert Krimen
83c56dd73d Add Otto.Call 2013-05-19 19:03:05 -07:00
Robert Krimen
3c139264ef Handle ToValue(nil) 2013-05-19 17:43:08 -07:00
Robert Krimen
adf21d0208 No rush to change the interface of Value.Export() 2013-05-15 19:30:39 -07:00
Robert Krimen
faaed09553 Change Export() to have new interface and slightly different behavior 2013-05-15 19:04:39 -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
6c5259a651 Add Object.toLocaleString 2013-05-02 21:06:22 +02:00
Robert Krimen
4c85422172 Make encodeURI correspond to the 15.1.3.3 algorithm and encodeURIComponent ito 15.1.3.4 2013-05-02 20:23:06 +02:00
Robert Krimen
f3da7237f2 Add Object.getPrototypeOf 2013-03-05 12:03:33 -08:00
Robert Krimen
795cc4935d Add remarks about ToValue & Otto.ToValue 2013-02-04 10:41:17 -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
Marty Schoch
5bac9a7a34 add Export capability to javascript Value
this allows you to export a javascript Value back
for use in go.  the result structure should be the
same as if you serialized to JSON in javascript
and then Unmarshal'd those bytes in go
2012-11-07 08:18:46 -05:00
Robert Krimen
3c93384f5c Cleanup of stash, property, and object
Use octal to designate write/enumerate/configure (experimental)
Move extensibility responsibility into the stash
Rename propertyStash => objectStash (be congruent with arrayStash, etc.)
Get rid of a bunch of useless methods
Privatize everything ([A-Z] => [a-z_])
gofmt
2012-10-26 15:47:19 -07:00
Robert Krimen
02929cbeb1 Shortcut the production of Object.Value() 2012-10-11 18:22:00 -07:00
Robert Krimen
4a8c7ffc00 Initial commit 2012-10-05 18:47:53 -07:00