aws / aws/aws-appsync-community

[JS] Behaviour of Array.prototype.join() incompatible with ECMAScript v6.0

Open
#335 0 comments 0 reactions 0 assignees View on GitHub
pending triage
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

## Issue description
The implementation of method `Array.prototype.join()` diverts from the official [ECMAScript (ES) version 6.0](https://262.ecma-international.org/6.0/) documentation. ECMAScript treats `undefined` and `null` elements as empty strings, while this custom proprietary runtime first converts them to `null`, then converts `null` to string and only then treats these double converted strings as elements:
```js
// ECMAScript v6.0
var officialA = ["foo", undefined].join("/"); // -> "foo/"
var officialB = ["foo", null].join("/"); // -> "foo/"

// AppSync
var customA = ["foo", undefined].join("/"); // -> "foo/null"
var customB = ["foo", null].join("/"); // -> "foo/null"
```

Read the relevant section here - https://262.ecma-international.org/6.0/#sec-array.prototype.join
\- under the procedure step `13.c` you'll find stated:
> If _element_ is `undefined` or `null`, let _next_ be the empty String; otherwise, let _next_ be [ToString](https://262.ecma-international.org/6.0/#sec-tostring)(_element_).

## Bug reproduction
See the reproducible bug demo here: https://github.com/testuj-to/appsync-esv6-incompatible-join
In the demo, 2 strings are expected to be returned (`"foo/"` and `"foo/"`), instead this is the output:
Screenshot 2023-11-12 at 2 09 28

Contributor guide

Open the contributing guide

Research direction

Start with the linked reproducible demo and compare its Array.prototype.join() results with step 13.c of the ECMAScript 6.0 specification. Confirm that undefined and null elements should produce empty strings, then determine where an AppSync runtime report or change can be made; done means both examples return "foo/".

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.