@@ -48,23 +48,22 @@ function ensureSafeMemberName(name, fullExpression) {
48
48
return name ;
49
49
}
50
50
51
- function getStringValue ( name , fullExpression ) {
52
- // From the JavaScript docs:
51
+ function getStringValue ( name ) {
53
52
// Property names must be strings. This means that non-string objects cannot be used
54
53
// as keys in an object. Any non-string object, including a number, is typecasted
55
54
// into a string via the toString method.
55
+ // -- MDN, https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors#Property_names
56
56
//
57
- // So, to ensure that we are checking the same `name` that JavaScript would use,
58
- // we cast it to a string, if possible.
59
- // Doing `name + ''` can cause a repl error if the result to `toString` is not a string,
60
- // this is, this will handle objects that misbehave.
61
- name = name + '' ;
62
- if ( ! isString ( name ) ) {
63
- throw $parseMinErr ( 'iseccst' ,
64
- 'Cannot convert object to primitive value! '
65
- + 'Expression: {0}' , fullExpression ) ;
66
- }
67
- return name ;
57
+ // So, to ensure that we are checking the same `name` that JavaScript would use, we cast it
58
+ // to a string. It's not always possible. If `name` is an object and its `toString` method is
59
+ // 'broken' (doesn't return a string, isn't a function, etc.), an error will be thrown:
60
+ //
61
+ // TypeError: Cannot convert object to primitive value
62
+ //
63
+ // For performance reasons, we don't catch this error here and allow it to propagate up the call
64
+ // stack. Note that you'll get the same error in JavaScript if you try to access a property using
65
+ // such a 'broken' object as a key.
66
+ return name + '' ;
68
67
}
69
68
70
69
function ensureSafeObject ( obj , fullExpression ) {
@@ -1231,7 +1230,7 @@ ASTCompiler.prototype = {
1231
1230
} ,
1232
1231
1233
1232
getStringValue : function ( item ) {
1234
- this . assign ( item , 'getStringValue(' + item + ',text )' ) ;
1233
+ this . assign ( item , 'getStringValue(' + item + ')' ) ;
1235
1234
} ,
1236
1235
1237
1236
ensureSafeAssignContext : function ( item ) {
0 commit comments