OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 339 |
340 | 340 |
341 | 341 |
342 /* ----------------------------- | 342 /* ----------------------------- |
343 - - - H e l p e r s - - - | 343 - - - H e l p e r s - - - |
344 ----------------------------- | 344 ----------------------------- |
345 */ | 345 */ |
346 | 346 |
347 // ECMA-262, section 11.4.1, page 46. | 347 // ECMA-262, section 11.4.1, page 46. |
348 function DELETE(key, strict) { | 348 function DELETE(key, strict) { |
349 return %DeleteProperty(%ToObject(this), %ToString(key), strict); | 349 return %DeleteProperty(%ToObject(this), %ToName(key), strict); |
350 } | 350 } |
351 | 351 |
352 | 352 |
353 // ECMA-262, section 11.8.7, page 54. | 353 // ECMA-262, section 11.8.7, page 54. |
354 function IN(x) { | 354 function IN(x) { |
355 if (!IS_SPEC_OBJECT(x)) { | 355 if (!IS_SPEC_OBJECT(x)) { |
356 throw %MakeTypeError('invalid_in_operator_use', [this, x]); | 356 throw %MakeTypeError('invalid_in_operator_use', [this, x]); |
357 } | 357 } |
358 return %_IsNonNegativeSmi(this) ? | 358 return %_IsNonNegativeSmi(this) ? |
359 %HasElement(x, this) : %HasProperty(x, %ToString(this)); | 359 %HasElement(x, this) : %HasProperty(x, %ToName(this)); |
360 } | 360 } |
361 | 361 |
362 | 362 |
363 // ECMA-262, section 11.8.6, page 54. To make the implementation more | 363 // ECMA-262, section 11.8.6, page 54. To make the implementation more |
364 // efficient, the return value should be zero if the 'this' is an | 364 // efficient, the return value should be zero if the 'this' is an |
365 // instance of F, and non-zero if not. This makes it possible to avoid | 365 // instance of F, and non-zero if not. This makes it possible to avoid |
366 // an expensive ToBoolean conversion in the generated code. | 366 // an expensive ToBoolean conversion in the generated code. |
367 function INSTANCE_OF(F) { | 367 function INSTANCE_OF(F) { |
368 var V = this; | 368 var V = this; |
369 if (!IS_SPEC_FUNCTION(F)) { | 369 if (!IS_SPEC_FUNCTION(F)) { |
(...skipping 19 matching lines...) Expand all Loading... |
389 | 389 |
390 // Return whether or not O is in the prototype chain of V. | 390 // Return whether or not O is in the prototype chain of V. |
391 return %IsInPrototypeChain(O, V) ? 0 : 1; | 391 return %IsInPrototypeChain(O, V) ? 0 : 1; |
392 } | 392 } |
393 | 393 |
394 | 394 |
395 // Filter a given key against an object by checking if the object | 395 // Filter a given key against an object by checking if the object |
396 // has a property with the given key; return the key as a string if | 396 // has a property with the given key; return the key as a string if |
397 // it has. Otherwise returns 0 (smi). Used in for-in statements. | 397 // it has. Otherwise returns 0 (smi). Used in for-in statements. |
398 function FILTER_KEY(key) { | 398 function FILTER_KEY(key) { |
399 var string = %ToString(key); | 399 var string = %ToName(key); |
400 if (%HasProperty(this, string)) return string; | 400 if (%HasProperty(this, string)) return string; |
401 return 0; | 401 return 0; |
402 } | 402 } |
403 | 403 |
404 | 404 |
405 function CALL_NON_FUNCTION() { | 405 function CALL_NON_FUNCTION() { |
406 var delegate = %GetFunctionDelegate(this); | 406 var delegate = %GetFunctionDelegate(this); |
407 if (!IS_FUNCTION(delegate)) { | 407 if (!IS_FUNCTION(delegate)) { |
408 throw %MakeTypeError('called_non_callable', [typeof this]); | 408 throw %MakeTypeError('called_non_callable', [typeof this]); |
409 } | 409 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 556 } |
557 | 557 |
558 function NonStringToString(x) { | 558 function NonStringToString(x) { |
559 if (IS_NUMBER(x)) return %_NumberToString(x); | 559 if (IS_NUMBER(x)) return %_NumberToString(x); |
560 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 560 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
561 if (IS_UNDEFINED(x)) return 'undefined'; | 561 if (IS_UNDEFINED(x)) return 'undefined'; |
562 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 562 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
563 } | 563 } |
564 | 564 |
565 | 565 |
| 566 // ES6 symbols |
| 567 function ToName(x) { |
| 568 return IS_SYMBOL(x) ? x : %ToString(x); |
| 569 } |
| 570 |
| 571 |
566 // ECMA-262, section 9.9, page 36. | 572 // ECMA-262, section 9.9, page 36. |
567 function ToObject(x) { | 573 function ToObject(x) { |
568 if (IS_STRING(x)) return new $String(x); | 574 if (IS_STRING(x)) return new $String(x); |
569 if (IS_NUMBER(x)) return new $Number(x); | 575 if (IS_NUMBER(x)) return new $Number(x); |
570 if (IS_BOOLEAN(x)) return new $Boolean(x); | 576 if (IS_BOOLEAN(x)) return new $Boolean(x); |
571 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | 577 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { |
572 throw %MakeTypeError('null_to_object', []); | 578 throw %MakeTypeError('null_to_object', []); |
573 } | 579 } |
574 return x; | 580 return x; |
575 } | 581 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 throw %MakeTypeError('cannot_convert_to_primitive', []); | 664 throw %MakeTypeError('cannot_convert_to_primitive', []); |
659 } | 665 } |
660 | 666 |
661 | 667 |
662 // NOTE: Setting the prototype for Array must take place as early as | 668 // NOTE: Setting the prototype for Array must take place as early as |
663 // possible due to code generation for array literals. When | 669 // possible due to code generation for array literals. When |
664 // generating code for a array literal a boilerplate array is created | 670 // generating code for a array literal a boilerplate array is created |
665 // that is cloned when running the code. It is essential that the | 671 // that is cloned when running the code. It is essential that the |
666 // boilerplate gets the right prototype. | 672 // boilerplate gets the right prototype. |
667 %FunctionSetPrototype($Array, new $Array(0)); | 673 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |