archives

« Bugzilla Issues Index

#3507 — 21.1.3.* GetMethod usage


While implementing the new versions of the String.prototype methods, I found I had to diverge from the specified algorithm slightly.

All of these methods use the following opening (but using String.p.replace as an example):

String.prototype.replace (searchValue, replaceValue )
1. Let O be RequireObjectCoercible(this value).
2. Let string be ToString(O).
3. ReturnIfAbrupt(string).
4. Let replacer be GetMethod(searchValue, @@replace).
5. ReturnIfAbrupt(replacer).
6. If replacer is not undefined, then
a. Return Call(replacer, searchValue, «string, replaceValue»).


GetMethod is being called on searchValue without first checking if searchValue is Type Object. This fails (crash on ejs) when the first arg to .replace is a primitive string.

Working backward from my code yields this algorithm fragment:

String.prototype.replace (searchValue, replaceValue )
1. Let O be RequireObjectCoercible(this value).
2. Let string be ToString(O).
3. ReturnIfAbrupt(string).
4. Let replacer be undefined
5. if Type(searchValue) is Object
a. Let replacer be GetMethod(searchValue, @@replace).
b. ReturnIfAbrupt(replacer).
6. If replacer is not undefined, then
a. Return Call(replacer, searchValue, «string, replaceValue»).

Am I missing some behavior of GetMethod (or something it calls?)


GetMethod was changed in rev30, it's now using GetV instead of Get.


(In reply to André Bargull from comment #1)
> GetMethod was changed in rev30, it's now using GetV instead of Get.

Ahhh, Thanks André. Missed that change in GetMethod.