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
KAS
3ca729876b
docs: improve grammar, clarity, and code examples (#548)
Improve grammar and clarity, fixing punctuation issues, improving
consistency in phrases and corrected minor code examples.
2025-06-13 17:08:31 +01:00
Harrison Ho
085142ee6c
feat: object assign (#547)
Implement object assign
2025-03-31 08:42:01 +01:00
Steven Hartland
43d0d58193
docs: clean up readme (#539)
Clean up readme apply fixes flagged by markdown linter and updating
URLs.
2024-11-05 09:52:49 +00:00
Steven Hartland
c9ce175a19
ci: update goreleaser args (#538)
Update goreleaser args to use the new non-deprecated --clean.
2024-11-04 11:07:44 +00:00
Steven Hartland
c136deb268
fix: string slice and replace (#535)
Fix string slice and replace so they work correctly with utf8
characters.

Fixes #534
2024-11-04 10:49:04 +00:00
Steven Hartland
aefc75aabc
chore: update go and tools (#537)
Update to the oldest supported release of go v1.22 at this time.

Update golangci-lint to 1.61.0 and address all issues.

Update actions to the latest versions.
2024-11-03 16:40:47 +00:00
Steven Hartland
a81d9a55bf
chore: update underscore to 1.13.7 (#536)
Update underscore to 1.13.7
2024-11-03 15:54:54 +00:00
psve
a39e65d406
Fix missing flag from regex literal in corner case (#529)
In the specific corner case where a regex contains a flag but is not
followed by any symbols, the ast.RegExpLiteral.Literal value would drop
(part of) that flag.

This happens because the p.next() call during the parsing of the flag
wouldn't actually advance the p.chrOffset, and thus endOffset would be
erroneously adjusted.

The fix is just to use the current p.chrOffset and then call p.next()
afterwards.
2024-07-09 17:20:35 +01:00
Filip Sandborg
d4edd51c4f
fix(parser/lexer): ID_Start & ID_Continue checks (#524)
Fix the checks for ID_Start & ID_Continue to match the definitions in
https://www.unicode.org/reports/tr31/
2024-06-12 10:20:22 +01:00
linuxerwang
2d23528df0
feat: support trailing comma after the last argument (#520)
Add support for trailing comma after the last argument of a method call.
2024-05-03 15:20:42 +01:00
rory malcolm
1ca7723e8a
feat: support Object.values() (#518)
Adds support for `Object.values()`
2024-04-13 18:15:49 +01:00
Steven Hartland
98effe01d8
chore: update ci versions (#519)
Update go, golangci-lint and action versions.

Address new lint failures flagged by updated golangci-lint version.
2024-04-13 17:05:50 +01:00
rory malcolm
b755419e33
feat: add trimStart and trimEnd aliases (#516)
Leverage  `trimRight` and `trimLeft` functions to provide `trimStart` and `trimEnd`.
2023-12-30 16:06:52 +00:00
rory malcolm
c902ab4346
feat: add string startsWith method (#514)
Adds startsWith method to the String builtins.
2023-12-19 19:17:47 +00:00
Tomoki Yamaguchi
9f9bfb98bd
fix: starting position of comment (#507)
Fix Begin of Comment to point to the position of the opening slash.
2023-08-16 19:08:32 +01:00
Tomoki Yamaguchi
11288b7564
fix: positions of statements (#506)
Fix the positions of various statements:
* Fix Idx1 of BranchStatement so that it points to the character after the label if Label exists,
  or the one after Token if Label does not exist.
* Fix Idx1 of LabelledStatement so that it points to the character after the statement.
* Fix Idx1 of ReturnStatement so that it points to the character after the argument if
  Argument exists, or the one after return keyword if Argument does not exist.
* Set Idx0 of SwitchStatement and fix Idx1 of SwitchStatement so that it points to the
  character after the right brace.
* Fix Idx0 of ThrowStatement to point to the start of throw keyword and fix Idx1 of
  ThrowStatement so that it points to the next character after Argument.
* Fix Idx1 of TryStatement to point to the character after Finally if Finally exists, or after Catch
  if Finally does not exist.
* Set Idx0 of WithStatement which was not previously set.
* Set WhileStatement.While so that Idx0 points to the right place.
* Set Idx0 of DoWhileStatement and fix Idx1 to point to the next character after the right
  parenthesis.
2023-07-25 18:25:01 +01:00
Tomoki Yamaguchi
589611c3ae
fix: positions of expressions (#505)
Fix Idx1 of ConditionalExpression so that it points to the next character after alternate expression.
Fix Idx1 of SequenceExpression to return Idx1 of the last sequence element, not first.
Fix Idx0 of unary expression to point to the start of operand in case of a postfix operator.
Fix Idx1 of VariableExpression so that it points to the character right after the name literal if the
expression does not have an initializer.
2023-07-21 22:47:33 +01:00
Tomoki Yamaguchi
d2ed0a776e
fix: Idx1 of ObjectLiteral and ArrayLiteral (#504)
Fix Idx1 of ObjectLiteral  so that it points to the character immediately after the right brace.

Fix Idx1 of ArrayLiteral so that it points to the character immediately after the right bracket.
2023-07-20 20:54:28 +01:00
Tomoki Yamaguchi
03572093ec
fix: starting positions of for and for-in statements (#503)
Fix Idx0 of ForStatement and ForInStatement to point to the right place which were previously not set.
2023-07-18 10:42:59 +01:00
Tomoki Yamaguchi
f70d418ad2
fix: starting position of if statement (#501)
Fix IfStatement Idx0 to point to the right place. I was pointing to the right parenthesis
after the test expression.
2023-07-17 22:27:09 +01:00
Steven Hartland
ea8bcc30d6
ci: fix lint failures (#502)
Fix lint failures introduced by new 1.53 linters
* Remove naked returns
* Accept times using local time where intended
* Allow unused parameter for now on call method
* Disable depguard which just seems to be noise

Also:
* Correct typo so we use the specified golangci-lint version in CI.
2023-07-16 19:17:11 +01:00
Conrad Pankoff
fc4074c616 fix: panic related to invalid property access in goMapObject
Ignore errors when converting a property name to the key type for goMapObject
during a getOwnProperty operation, as a property which fails conversion to the
target's key type could not possibly be a member of it.

fixes #488
2023-07-10 20:21:40 +10:00
Conrad Pankoff
67dbb5d65b fix: mishandling of message parameter in runtime.newErrorObject
runtime.newErrorObject is used to implement the Error constructor, and as such
it takes input from JavaScript via calls like `new Error('xxx')`. The actual
underlying error information is stored in an ottoError object, which is
constructed using newError. newError takes a couple of mandatory arguments,
then treats the remaining parameters (collected as `in ...interface{}`) as a
printf-style format string and parameter list, which it uses to populate the
message field of the returned ottoError object. newErrorObject was passing the
message parameter from the Error function exposed to JavaScript directly
through to newError as the first optional parameter, which led to it being
treated as a format string, which resulted in any code like `throw new
Error('%s')` behaving incorrectly, with the resultant error having a message
like "%!s(MISSING)".

This change fixes this behaviour in the least intrusive way I could find, and
adds some tests to make sure it doesn't come back.

The logic for newErrorObject and newErrorObjectError are very similar, so it
was tempting to try to merge them, but it appears they're used in somewhat
fragile ways with very little test coverage so I'll leave that as a problem
for another day.
2023-07-06 20:41:55 +10:00
Steven Hartland
922144077c
feat: date parse with slashes (#490)
Add support for parsing date times with slashes.

Fixes #489

Also:
* Disable G307 for read only files.
* Add missing yaml tag to jsType.
2023-05-22 17:23:07 +01:00
amaicode
f987875222
fix: panic on BadStatement (#495)
Add BadStatement case to walk.go to fix panic if there's bad code.
2023-05-20 13:35:41 +01:00
Steven Hartland
fbcfda961e
ci: fix golangci-lint errors (#496)
Fix golangci-lint errors triggered by new version.

Disable deprecated linters.
2023-05-19 13:04:21 +01:00
HuKai
2b00d85b5e
feat: add math function (#485)
Add some ES6 math functions.
2023-02-23 16:13:49 +00:00
Steven Hartland
b882379002
chore: add generated headers (#486)
Add headers to generated files so that editors will notify users that
these files shouldn't be edited manually.
2023-01-13 19:47:05 +00:00
Steven Hartland
802621d091
chore: improve error message (#484)
Improve panic error message by describing its function for clarity.
2022-12-07 00:24:38 +00:00
Steven Hartland
5d81e9e02d
chore: rename _parser (#483)
Rename _parser -> parser missed in previous refactor.
2022-12-07 00:23:10 +00:00
Steven Hartland
ddcbf14a26
chore: improve error messages (#482)
Improve error messages so we don't just get TypeError with no clue what
the issue was.
2022-12-07 00:13:42 +00:00
Steven Hartland
7927fb4a26
chore: add missing generate (#481)
Add missing generate for inline.go
2022-12-06 21:49:48 +00:00
Steven Hartland
f142365067
chore: add missing inline tests (#479)
Add inline tests missed in PR #476.
2022-12-05 23:21:23 +00:00
Steven Hartland
9230e2b888
fix: tester (#478)
Fix the way tester works, move it into the tools directory and clean up
how it processes files including adding more data to the summary about
what failed and why.
2022-12-05 23:15:21 +00:00
Steven Hartland
898a889ed4
fix: missing regexp capture panic (#477)
Fix RegExp panic when a capture doesn't match but the full expression
does.
2022-12-05 22:51:22 +00:00
Steven Hartland
233dfa4ef0
chore: remove perl, make and local docs. (#476)
Remove the dependencies on perl and make.

inline.pl is replaced by tools/gen-jscore and token/tokenfmt is replaced
by tools/gen-tokens which are both golang text/template utilities.

gen-jscore uses property ordering that matches chromes output ordering
adding missing properties to the Error types.

Local generated documentation have been removed as https://pkg.go.dev/
is more feature rich.

The use of make has been removed as the functionality is now replicated by
standard golang tools go test ./... and go generate ./... as well as integrated
into github actions.
2022-12-05 22:19:34 +00:00
Steven Hartland
026a1d9a9c
chore: lint and naming refactor (#475)
Enable more linters, address the issues and do a major naming refactor
to use golang lower camelCase identifiers for types, functions, methods
and variable names.

Also: 
* Clean up inline generation so it doesn't rely on temporary variables.
* Remove unused functions generated by inline.pl.
2022-12-04 21:49:38 +00:00
Steven Hartland
70918b6218
fix: number to int conversions (#474)
Fix toInt32, toUint32 conversions which caused test failures on arm64 by
leveraging the power of go casts to simplify the conversion from float64
to integer types.
2022-11-30 17:55:35 +00:00
Steven Hartland
242e87ac0e
fix(ast): invalid idx1 for new expression (#473)
Fix invalid Idx1() return for NewExpression when there are no
parenthesis.

Fixes #261
2022-11-29 13:55:47 +00:00
Steven Hartland
7de4257c77
fix: number locale support (#472)
Add support for Number.toLocaleString() which was previously just using
toString.

Default locale is: en-US

Fixes #285
2022-11-29 12:57:48 +00:00
Steven Hartland
93fb47cccc
fix(ast): walk missing nodes (#471)
Fix ast.Walk missing out:
* DotExpressions.Identifier
* LabelledStatement.Label

Fixes #299
2022-11-29 11:09:56 +00:00
Steven Hartland
8d121dcad1
feat(underscore)!: update to v1.13.6 (#470)
Update underscore.js to v1.13.6.

BREAKING CHANGE: This changes the behaviour for the following underscore
functions, please see underscore.js documentation for details.
* .template
* .keys
* .after
* .range
* .reduce
* .reduceRight
* .reduceLeft

Fixes #110
2022-11-29 00:09:10 +00:00
R. Aidan Campbell
4617108200
fix: example to clean up watchdog goroutine (#431)
Fix the example to clean up watchdog goroutine after either the timeout or the VM completes.

Co-authored-by: Steven Hartland <steven.hartland@multiplay.co.uk>
2022-11-29 00:08:50 +00:00
Steven Hartland
ad8875609a
feat: use exported methods when setting go values (#469)
When putting JavaScript objects into _go*object use exported values.
This reverts PR #467 in favour of this more complete work.

Fixes #118 #252

Co-authored-by: Dmitry Panov <dop@itoolabs.com>
2022-11-28 20:58:40 +00:00
Steven Hartland
eb72a6e703
fix: reduce current index type (#468)
While not specified in the ECMA specification the current index has been
typed as number by others, so match this instead of passing as string.

Fixes #177
2022-11-28 18:59:19 +00:00
Steven Hartland
ec2dc5ec24
fix: map export (#467)
When exporting a map check for values which are otto.Value and process
them. This is a one level export and no additional traversal is done.

Fixes #252
2022-11-28 17:21:20 +00:00
Steven Hartland
c745096260
fix: regexp substring matches (#466)
Set RegExp.input, RegExp.$_ and RegExp.$1 -> $9 substring matches on
successful match.

Fixes #317
2022-11-28 15:50:55 +00:00
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
aeda017882
fix!: date underflow / overflow and utc (#464)
Use time.UnixMilli instead of UnixNano for time calculations to avoid
underflow / overflow issues.

BREAKING CHANGE: Use a GMT fixed time zone for UTC to mimic toUTCString
behaviour of Javascript which outputs in GMT not UTC.

Fixes #302
2022-11-28 13:00:51 +00:00
Steven Hartland
a5b0adea00
Allow semicolon in nested do-while statements. (#463)
In nested do-while statements, a semicolon after the inner `while` threw
a parsing error. This change checks for the optional semicolon.

Co-authored-by: Brian Graham <bcgraham+github@gmail.com>
2022-11-28 11:25:15 +00:00