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

93 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
a3b51c68f2
chore: enable whitespace linter and fix errors (#456)
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.
2022-11-26 13:33:09 +00: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
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
Robert Krimen
ed456945de Improve error reporting (again) 2014-06-21 21:16:58 -07: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
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
Igor Kharin
1864a88fa0 Implement strings without value16
This fixes #68

Some changes over the original patch, removing references to utf8string.String:

* (better) This removes a dependency on a non-standard (though solid) package
* (better) utf8string.String has mutable parts
* (worse) utf8string.String has a smarter consecutive access approach (by
  remembering where the last access was)
* (?) _stringWide allocates a []rune if charAt or charCodeAt access is needed (though
  it will only do this once for the string object)
2014-05-18 12:38:15 -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
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
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
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
61a011e711 Add Object.getOwnPropertyNames (sdgoij) 2013-06-04 20:07:16 -07:00
Robert Krimen
716c307c8d Add Date.toDateString, Date.toTimeString 2013-06-04 19:56:03 -07:00
Robert Krimen
f3d41e0b0c Fix Object built-in attribute defaults (true, false, true) 2013-06-03 18:36:24 -07:00
Robert Krimen
32164a41c9 Fix Date built-in attribute defaults (true, false, true) 2013-06-03 18:36:24 -07:00
Robert Krimen
55565afada Fix global built-in attribute defaults (true, false, true) 2013-06-03 18:36:06 -07:00
Robert Krimen
c6e033bf6c Fix Array initialization (in the case of [,...], etc.) 2013-06-02 16:41:34 -07:00
Robert Krimen
1b469aefc1 Add Object.keys (sdgoij) 2013-06-02 16:13:45 -07:00
Robert Krimen
baf3318f30 Add Error.prototype.message 2013-06-02 15:03:33 -07:00
Robert Krimen
599d565e55 Use defineOwnProperty (not put) for Array (literal) initialization 2013-06-01 23:11:13 -07:00
Robert Krimen
d2eaa4aab6 Add Object.seal (sdgoij) 2013-05-18 15:56:52 -07:00
Robert Krimen
15539ede6c Add Object.freeze (sdgoij) 2013-05-12 14:54:47 -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
d1d4d939ea Add Object.isSealed & Object.isFrozen 2013-05-05 10:35:32 -07:00
Robert Krimen
683e3956aa Add Object.isExtensible & Object.preventExtensions...
...and fix the deep implementation of defineOwnProperty
so that they can work (more or less) properly
2013-05-03 22:24:51 +02:00
Robert Krimen
6c5259a651 Add Object.toLocaleString 2013-05-02 21:06:22 +02:00
Robert Krimen
596af0a836 Fix RegExp.prototype.toString .length & .prototype 2013-05-02 20:23:07 +02:00
Robert Krimen
bc84827b09 Fix RegExp.prototype.test .length & .prototype 2013-05-02 20:23:07 +02:00
Robert Krimen
fc569ab73a Fix RegExp.prototype.exec .length & .prototype 2013-05-02 20:23:07 +02:00
Robert Krimen
b078bacaf7 Set the prototype of Math to the global object prototype 2013-05-02 20:23:07 +02:00
Robert Krimen
b4a6286aa7 Use RegExp._RegExp.Flags when doing new RegExp(RegExp) 2013-05-02 20:23:07 +02:00
Robert Krimen
5c5dfbf501 Use RegExp.source (not RegExp.toString) when doing new RegExp(RegExp) 2013-05-02 20:23:06 +02:00
Robert Krimen
74a8739188 Cannot supply flags when constructing one RegExp from another 2013-05-02 20:23:06 +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
83d4565b22 Make decodeURI correspond to the 15.1.3.1 algorithm and decodeURIComponent ito 15.1.3.2 2013-05-02 20:23:06 +02:00
Robert Krimen
b477d8eaed Fix isNaN/isFinite .length & .prototype 2013-04-30 00:18:00 +02:00
Robert Krimen
16030f4b6f Make parseInt behavior correspond to the 15.1.2.3 algorithm 2013-04-30 00:18:00 +02:00
Robert Krimen
b5e40f8a85 Make parseInt behavior correspond to the 15.1.2.2 algorithm 2013-04-28 17:33:00 +02:00
Robert Krimen
2ec9b0843c eval is not a constructor 2013-04-28 11:29:20 +02:00
Robert Krimen
6a4e5a904e eval.prototype === undefined 2013-04-28 11:25:06 +02:00
Robert Krimen
2c4c22ca81 eval.length === 1 2013-04-28 11:24:39 +02:00
Robert Krimen
cc112ca544 Set the prototype of the global object to be the object prototype 2013-04-28 11:00:21 +02:00
Robert Krimen
0da0545485 Add Array.isArray 2013-04-17 11:05:32 -07:00
Robert Krimen
fa871c8828 Add Date.toGMTString 2013-04-16 23:02:51 -07:00
Robert Krimen
d223d7576f Add Date.toLocale*String 2013-04-16 23:00:24 -07:00
Robert Krimen
9281104552 Add Date.setYear 2013-04-16 22:44:15 -07:00
Robert Krimen
d5497fbe89 Add Date.getYear 2013-04-16 22:37:17 -07:00