@@ -48,23 +48,22 @@ function ensureSafeMemberName(name, fullExpression) {
4848 return name ;
4949}
5050
51- function getStringValue ( name , fullExpression ) {
52- // From the JavaScript docs:
51+ function getStringValue ( name ) {
5352 // Property names must be strings. This means that non-string objects cannot be used
5453 // as keys in an object. Any non-string object, including a number, is typecasted
5554 // into a string via the toString method.
55+ // -- MDN, https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors#Property_names
5656 //
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 + '' ;
6867}
6968
7069function ensureSafeObject ( obj , fullExpression ) {
@@ -1231,7 +1230,7 @@ ASTCompiler.prototype = {
12311230 } ,
12321231
12331232 getStringValue : function ( item ) {
1234- this . assign ( item , 'getStringValue(' + item + ',text )' ) ;
1233+ this . assign ( item , 'getStringValue(' + item + ')' ) ;
12351234 } ,
12361235
12371236 ensureSafeAssignContext : function ( item ) {
0 commit comments