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

753 Commits

Author SHA1 Message Date
Steven Hartland
762556bdd2
fix: constant overflow for date tests (#462)
Fix constant overflow for date tests on 32bit architectures which have
int as 32bit not 64bit.

Fixes #351
2022-11-27 23:26:41 +00:00
Steven Hartland
f76dda1760
feat: error with stack on %#v (#461)
Print the error with stack when using %#v.

Fixes #363
2022-11-27 23:12:50 +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
e92282a6bb
fix: javascript sort time (#459)
Reduce the item count in JavaScript sort benchmarks to something more
reasonable given the memory pressure they cause.

Fixes #378
2022-11-27 20:09:54 +00:00
andig
3cf1fcc1d8
chore: update to go 1.18 (#458)
Upgrade go.mod to a supported version.
2022-11-27 20:09:40 +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
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
b6f2991c96
chore: clean up issue tests (#453)
Move all issue tests into issue_test.go and use common naming
convention.
2022-11-26 00:44:36 +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
4c4631625a
fix: string lengths (#450)
Fix string lengths for strings containing code points which require a
Surrogate pair encoding in utf16.

Fixes #388
2022-11-25 21:35:14 +00:00
Steven Hartland
9163a3ee27
ci: enable golangci-lint cache (#451)
Remove skip-cache: true and restore skip-pkg-cache: true and
skip-build-cache: true so that we still cache golangci-lint results
which skip-cache: true disables.
2022-11-25 21:34:48 +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
ba066df8fc
ci: use setup-go caching (#448)
Use setup-go caching instead of manually rolled version.

Also:
* Bump golangci-lint to 1.50.1.
* Add go 1.19 to test / lint matrix.
* Bump timeout to 6 mins.
2022-11-25 15:00:07 +00:00
Steven Hartland
93072360ee
ci: add goreleaser (#447)
Add goreleaser to enable the easy creation of otto releases.
2022-11-25 13:29:41 +00:00
Erik Nordmark
511d75fba9
chore: update logex (#442)
Update github.com/chzyer/logex to v1.2.1 which has an explicit
LICENSE file to prevent package without alarming compliance
tools.

Signed-off-by: eriknordmark <erik@zededa.com>
2022-10-25 14:53:07 +01:00
Jens Alfke
09fc211e5a
feat: implement MarshalJSON for Value and Object (#437)
Value and Object now conform to the json.Marshaler interface and produce the
correct JSON when passed (directly or indirectly) to json.Marshal().

Before, both types would marshal as "{}" because they're structs with no public
fields.

This fixes some nasty problems marshaling object trees that mix Go and JS
collections. This can happen when you pass a Go collection into a JS function,
which modifies it adding JS values; and then back in Go you marshal the
collection to JSON. Before this commit the JS values would marshal to "{}".
(The new unit test TestNestedJSONMarshaling demonstrates this.)

Fixes #262
2022-10-11 18:56:42 +01:00
Steven Hartland
7009038f79
fix: linting errors (#441)
Disable new linters which aren't compatible with this code module.

Upgrade github actions to fix caching issues.

Run go mod to bring in new styling.

Remove space on nolint declarations.

Apply all changes to whitespace as required to pass goimports linter.

Only trigger checks on pull_request which works for pulls from other
forks, where as push only works from the same repo.
2022-10-08 00:12:19 +01:00
Richard Putra
201ab5b34f
fix: timeout on empty loop (#440)
Prevent loop statements with no body hanging forever

Co-authored-by: Stefano Fratini <stefano.fratini@nnnco.com.au>
Co-authored-by: tkpd-richard-putra <83326962+tkpd-richard-putra@users.noreply.github.com>
2022-10-06 12:45:23 +01:00
shahinv
b87d35c0b8
fix: remove unnecessary len (#424)
Remove extra len call on target variable
2021-10-24 18:01:58 +01:00
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
andig
4eacda02dd
fix: uint<0 comparisons (#421)
Remove impossible conditions for uint comparisons.
2021-10-08 09:47:15 +01:00
Douglas Thrift
12a6322603
fix: export when an array has multiple types (#387)
Fix a panic in value export when an array has multiple types of arrays.

This takes into account the types of elements in sub arrays, slices, etc.

Fixes #279
Fixes #377
2021-10-04 14:44:30 +01:00
Steven Hartland
f9375a2569
fix: golang style (#420)
Fix golang style which was broken by github suggestions spacing.
2021-09-27 23:22:13 +01:00
Boris Kostenko
6d2823e7c9
fix: array sort (#267)
Fix array sort issue using toIntSign compare function 

Fixes #266
2021-09-27 22:59:40 +01: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
Iskander (Alex) Sharipov
ca9b4f9067
fix: replace single case type switches with if (#322)
Replace single case type switches with if statement.

Found using https://go-critic.github.io/overview.html#singleCaseSwitch-ref
2021-09-27 16:47:34 +01:00
Iskander (Alex) Sharipov
818f7465f8
fix(underscore): remove unneeded wrapping lambda (#320)
Use func value instead of wrapping lambda

Found using https://go-critic.github.io/overview.html#unlambda-ref
2021-09-27 16:34:54 +01:00
Iskander (Alex) Sharipov
43d26482c3
fix: remove unnecessary dereference (#321)
Removed unneeded dereference in builtinJSON_stringifyWalk:
Found using https://go-critic.github.io/overview.html#underef-ref
2021-09-27 16:32:26 +01:00
Iskander (Alex) Sharipov
edceeed7a9
fix: remove commented-out code (#323)
Remove old commented out code that was found using:
https://go-critic.github.io/overview.html#commentedOutCode-ref
2021-09-27 16:31:07 +01:00
Iskander (Alex) Sharipov
d34fc6f56d
fix: scope.reset, set length to 0 (#324)
Fix scope.reset to correctly clear output, while maintaining
the slice size.
2021-09-27 16:30:05 +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
Steven Hartland
209b1fb8e8
Revert "feat: support null value returns for toValue (#325)" (#417)
This reverts commit 26cb6ccce6.
2021-09-27 12:00:52 +01:00
Ryan
26cb6ccce6
feat: support null value returns for toValue (#325)
Add nullValue as the return value for the nil case in toValue.

Co-authored-by: Ryan Macleod <ryan.macleod@cumul8.com>
2021-09-27 11:47:21 +01:00
Jongmin Kim
67c8da69a8
fix: test timeout on slow machines (#340)
Fix test timeout on slow machines by extend testing timeout
to 20 secs.

Fixes: #337

Signed-off-by: Jongmin Kim <jmkim@pukyong.ac.kr>
2021-09-27 11:38:29 +01:00
ilyapashuk
08d7b51940
feat: add go.mod support (#376)
Add support for go mod
2021-09-27 11:13:58 +01:00
Robert-André Mauchin
dee429e322
fix: go vet 1.15 warnings (#385)
Convert int to string using rune()

See https://github.com/golang/go/issues/32479

Fix #384.

Signed-off-by: Robert-André Mauchin <zebob.m@gmail.com>
2021-09-27 11:11:52 +01:00
Luka Zakrajšek
373ff54384
fix: Incorrect groups offsets if lastIndex is set (#393) 2021-06-14 19:17:06 +01:00
Conrad Pankoff
ef014fd054 improve error messages when converting values 2020-09-23 08:17:31 +10:00
Conrad Pankoff
c382bd3c16 fix field accesses on anonymous embedded structs 2019-12-20 10:40:10 +11:00
Conrad Pankoff
37f8e9a246 support Number.isNaN 2019-12-17 17:34:20 +11:00
Conrad Pankoff
9fa7c0c0f8 support converting to json.RawMessage 2019-12-15 13:36:24 +11:00
Conrad Pankoff
b839e7b8bb support methods on go array values 2019-12-15 13:18:22 +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
ia
15f95af6e7 all: gofmt (#307)
Run standard gofmt command on project root.

- go version go1.10.3 darwin/amd64

Signed-off-by: ia <isaac.ardis@gmail.com>
2018-06-17 14:11:54 +01: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