This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Add minimal specification #13
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,25 +28,19 @@ <h1>String.prototype.replaceAll ( _searchValue_, _replaceValue_ )</h1> | |||||
<p>When the `replaceAll` method is called with arguments _searchValue_ and _replaceValue_, the following steps are taken:</p> | ||||||
<emu-alg> | ||||||
1. Let _O_ be ? RequireObjectCoercible(*this* value). | ||||||
1. If _searchValue_ is neither *undefined* nor *null*, then | ||||||
1. Let _replacer_ be ? GetMethod(_searchValue_, @@replace). | ||||||
1. If _replacer_ is not *undefined*, then | ||||||
1. Return ? Call(_replacer_, _searchValue_, « _O_, _replaceValue_ »). | ||||||
1. Let _string_ be ? ToString(_O_). | ||||||
1. Let _searchString_ be ? ToString(_searchValue_). | ||||||
1. Let _functionalReplace_ be IsCallable(_replaceValue_). | ||||||
1. If _functionalReplace_ is *false*, then | ||||||
1. Set _replaceValue_ to ? ToString(_replaceValue_). | ||||||
1. Search _string_ for the first occurrence of _searchString_ and let _pos_ be the index within _string_ of the first code unit of the matched substring and let _matched_ be _searchString_. If no occurrences of _searchString_ were found, return _string_. | ||||||
1. If _functionalReplace_ is *true*, then | ||||||
1. Let _replValue_ be ? Call(_replaceValue_, *undefined*, « _matched_, _pos_, _string_ »). | ||||||
1. Let _replStr_ be ? ToString(_replValue_). | ||||||
1. Let _isRegExp_ be ? IsRegExp(_searchValue_). | ||||||
1. If _isRegExp_ is *true*, then | ||||||
1. Let _flags_ be _searchValue_.[[OriginalFlags]]. | ||||||
1. If _flags_ does not contain `"g"`, then | ||||||
1. Set _flags_ to a copy of _flags_. | ||||||
1. Append `"g"` to _flags_. | ||||||
1. Else, | ||||||
1. Let _captures_ be a new empty List. | ||||||
1. Let _replStr_ be GetSubstitution(_matched_, _string_, _pos_, _captures_, *undefined*, _replaceValue_). | ||||||
1. Let _tailPos_ be _pos_ + the number of code units in _matched_. | ||||||
1. Let _newString_ be the string-concatenation of the first _pos_ code units of _string_, _replStr_, and the trailing substring of _string_ starting at index _tailPos_. If _pos_ is 0, the first element of the concatenation will be the empty String. | ||||||
1. Return _newString_. | ||||||
1. Let _searchString_ be ? ToString(_searchValue_). | ||||||
1. Set _escapedPattern_ to EscapeRegExpPattern(_src_, `"g"`). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
1. Set _searchValue_ to ? RegExpCreate(_escapedPattern_, `"g"`). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So... We add |
||||||
1. Assert: ! IsRegExp(_searchValue_) is *true*. | ||||||
1. Let _replacer_ be ? GetMethod(_searchValue_, @@replace). | ||||||
1. Return ? Call(_replacer_, _searchValue_, « _O_, _replaceValue_ »). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could also just call |
||||||
</emu-alg> | ||||||
<emu-note> | ||||||
<p>The `replaceAll` function is intentionally generic; it does not require that its *this* value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.</p> | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? This is a value, not a reference to the internal slot on searchValue.
Alternatively, there’s an existing form of “to the concatenation of a and b” that’s probably better here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s not what https://tc39.github.io/ecma262/#sec-algorithm-conventions says:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, that seems terrifying :-) either way i think the concatenation language would be simpler (it’s what matchAll uses)