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

27 Commits

Author SHA1 Message Date
amartin
5b0d97091c
feat: basic non ascii support (#423)
Adds basic non ascii support including substring, substr, slice functions,
which work with runes (prevent utf-8 length).

This includes adding runes compatible functions:
* indexOf
* lastIndexOf
2021-10-19 18:51:42 +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
Robert Krimen
284b08b295 Restore .split returning a proper Array (fix #234) 2017-01-13 18:35:26 -08:00
David P Hilton
7427d59429 made string splits *much* faster 2016-09-22 14:52:38 -06: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
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
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
1df390a237 Fix String.prototype.lastIndexOf 2014-01-24 21:20:22 -08:00
Robert Krimen
60b6d1190f Fix String.prototype.indexOf to return the right index even with an offset 2014-01-24 21:20:22 -08:00
Robert Krimen
b49fd47f78 Fix special case in String.prototype.split 2014-01-24 21:20:22 -08:00
Robert Krimen
f0aa5da996 Fix off-by-one error with $' in String.prototype.replace 2014-01-24 21:20:22 -08:00
Robert Krimen
33672f5c98 Add String.toLocaleUpperCase 2013-07-14 14:38:59 -07:00
Robert Krimen
3d883a981e Add String.toLocaleLowerCase 2013-07-14 14:35:50 -07:00
Robert Krimen
1481c43476 Add String.trim (robertkrimen) 2013-07-14 14:20:01 -07:00
Robert Krimen
19360eafc4 Add String.localeCompare 2013-07-14 14:20:01 -07:00
Tim Jurcka
dd7d387420 Add String.prototype.trim(), and non-standard trimLeft(), trimRight()
This fixes #32
2013-07-14 14:19:06 -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
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
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
3c9faa2810 Fix String.char*At to look at utf16 version 2013-02-21 14:25:04 -08:00
Robert Krimen
bf322e56ee Fix subtle range bug in String.substring (uint => int64)
Was looking for negative in the following calculation:

uint(0) - uint(3) => uint(0)
2013-02-20 16:24:01 -08:00
Robert Krimen
ec902a6452 Split builtin.go out to builtin_*.go 2013-02-20 15:58:45 -08:00