@@ -39,7 +39,7 @@ pub(crate) fn string_exotic_get_own_property(
3939 Ok ( desc)
4040 } else {
4141 // 4. Return ! StringGetOwnProperty(S, P).
42- Ok ( string_get_own_property ( obj, key) )
42+ string_get_own_property ( obj, key)
4343 }
4444}
4545
@@ -57,7 +57,7 @@ pub(crate) fn string_exotic_define_own_property(
5757) -> JsResult < bool > {
5858 // 1. Assert: IsPropertyKey(P) is true.
5959 // 2. Let stringDesc be ! StringGetOwnProperty(S, P).
60- let string_desc = string_get_own_property ( obj, key) ;
60+ let string_desc = string_get_own_property ( obj, key) ? ;
6161
6262 // 3. If stringDesc is not undefined, then
6363 if let Some ( string_desc) = string_desc {
@@ -133,7 +133,10 @@ pub(crate) fn string_exotic_own_property_keys(
133133/// - [ECMAScript reference][spec]
134134///
135135/// [spec]: https://tc39.es/ecma262/#sec-stringgetownproperty
136- fn string_get_own_property ( obj : & JsObject , key : & PropertyKey ) -> Option < PropertyDescriptor > {
136+ fn string_get_own_property (
137+ obj : & JsObject ,
138+ key : & PropertyKey ,
139+ ) -> JsResult < Option < PropertyDescriptor > > {
137140 // 1. Assert: S is an Object that has a [[StringData]] internal slot.
138141 // 2. Assert: IsPropertyKey(P) is true.
139142 // 3. If Type(P) is not String, return undefined.
@@ -143,20 +146,23 @@ fn string_get_own_property(obj: &JsObject, key: &PropertyKey) -> Option<Property
143146 // 7. If index is -0𝔽, return undefined.
144147 let pos = match key {
145148 PropertyKey :: Index ( index) => index. get ( ) as usize ,
146- _ => return None ,
149+ _ => return Ok ( None ) ,
147150 } ;
148151
149152 // 8. Let str be S.[[StringData]].
150153 // 9. Assert: Type(str) is String.
151154 let string = obj
152155 . downcast_ref :: < JsString > ( )
153- . expect ( "string exotic method should only be callable from string objects" )
156+ . js_expect ( "string exotic method should only be callable from string objects" ) ?
154157 . clone ( ) ;
155158
156159 // 10. Let len be the length of str.
157160 // 11. If ℝ(index) < 0 or len ≤ ℝ(index), return undefined.
158- // 12. Let resultStr be the String value of length 1, containing one code unit from str, specifically the code unit at index ℝ(index).
159- let result_str = string. get ( pos..=pos) ?;
161+ // 12. Let resultStr be the String value of length 1, containing one code unit from str,
162+ // specifically the code unit at index ℝ(index).
163+ let Some ( result_str) = string. get ( pos..=pos) else {
164+ return Ok ( None ) ;
165+ } ;
160166
161167 // 13. Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }.
162168 let desc = PropertyDescriptor :: builder ( )
@@ -166,5 +172,5 @@ fn string_get_own_property(obj: &JsObject, key: &PropertyKey) -> Option<Property
166172 . configurable ( false )
167173 . build ( ) ;
168174
169- Some ( desc)
175+ Ok ( Some ( desc) )
170176}
0 commit comments