archives

« Bugzilla Issues Index

#4327 — String.prototype.search(null) causes TypeError, different from ES5


Reported in https://esdiscuss.org/topic/string-prototype-search-has-a-breaking-change-from-es5

Seeing ES6 String.prototype.search, there's a breaking change from ES5.

When executing `"gnulluna".search(null)`,

In ES5, RegExp(null) => /null/ is generated, so the result becomes 1.

http://ecma-international.org/ecma-262/5.1/#sec-15.5.4.12

In ES6, we fall down to the 21.1.3.15 step 3 (because null is not undefined).
And then reaching step 3.a,

Let searcher be GetMethod(regexp, @@search).

Then TypeError is thrown by GetV's ToObject.

Probably, String.prototype.{match, replace, split} also have the same issue.


FYI, WebKit issue is here. https://bugs.webkit.org/show_bug.cgi?id=143889


fixed in rev39 publication draft

line 3 of search should be

3. If regexp is neither undefined nor null, then

Also, equivalent change in match, replace, split.


(In reply to Allen Wirfs-Brock from comment #2)
> fixed in rev39 publication draft
>
> line 3 of search should be
>
> 3. If regexp is neither undefined nor null, then
>
> Also, equivalent change in match, replace, split.

Cool! Thank you.