Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: src/v8natives.js

Issue 7080053: Make instanceof and Object.getPrototypeOf work for proxies, plus a few other tweaks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 desc.setSet(set); 392 desc.setSet(set);
393 } 393 }
394 394
395 if (IsInconsistentDescriptor(desc)) { 395 if (IsInconsistentDescriptor(desc)) {
396 throw MakeTypeError("value_and_accessor", [obj]); 396 throw MakeTypeError("value_and_accessor", [obj]);
397 } 397 }
398 return desc; 398 return desc;
399 } 399 }
400 400
401 401
402 // For Harmony proxies.
403 function ToCompletePropertyDescriptor(obj) {
404 var desc = ToPropertyDescriptor(obj)
405 if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) {
406 if (!("value" in desc)) desc.value = undefined
Kevin Millikin (Chromium) 2011/06/01 15:14:31 undefined ==> void 0
407 if (!("writable" in desc)) desc.writable = false
408 } else {
409 // Is accessor descriptor.
410 if (!("get" in desc)) desc.get = undefined
411 if (!("set" in desc)) desc.set = undefined
412 }
413 if (!("enumerable" in desc)) desc.enumerable = false
414 if (!("configurable" in desc)) desc.configurable = false
415 return desc
416 }
417
418
402 function PropertyDescriptor() { 419 function PropertyDescriptor() {
403 // Initialize here so they are all in-object and have the same map. 420 // Initialize here so they are all in-object and have the same map.
404 // Default values from ES5 8.6.1. 421 // Default values from ES5 8.6.1.
405 this.value_ = void 0; 422 this.value_ = void 0;
406 this.hasValue_ = false; 423 this.hasValue_ = false;
407 this.writable_ = false; 424 this.writable_ = false;
408 this.hasWritable_ = false; 425 this.hasWritable_ = false;
409 this.enumerable_ = false; 426 this.enumerable_ = false;
410 this.hasEnumerable_ = false; 427 this.hasEnumerable_ = false;
411 this.configurable_ = false; 428 this.configurable_ = false;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 557 }
541 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); 558 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]);
542 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); 559 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]);
543 560
544 return desc; 561 return desc;
545 } 562 }
546 563
547 564
548 // ES5 section 8.12.2. 565 // ES5 section 8.12.2.
549 function GetProperty(obj, p) { 566 function GetProperty(obj, p) {
567 if (%IsJSProxy(obj)) {
568 var handler = %GetHandler(obj)
569 var getProperty = handler.getPropertyDescriptor
570 if (IS_UNDEFINED(getProperty))
571 throw MakeTypeError("handler_trap_missing",
572 [handler, "getPropertyDescriptor"])
573 var descriptor = getProperty.call(handler, p)
574 if (IS_UNDEFINED(descriptor)) return descriptor
575 var desc = ToCompletePropertyDescriptor(descriptor)
576 if (!desc.configurable)
577 throw MakeTypeError("proxy_prop_not_configurable",
578 [handler, "getPropertyDescriptor", p, descriptor])
579 return desc
580 }
550 var prop = GetOwnProperty(obj); 581 var prop = GetOwnProperty(obj);
551 if (!IS_UNDEFINED(prop)) return prop; 582 if (!IS_UNDEFINED(prop)) return prop;
552 var proto = obj.__proto__; 583 var proto = %GetPrototype(obj);
553 if (IS_NULL(proto)) return void 0; 584 if (IS_NULL(proto)) return void 0;
554 return GetProperty(proto, p); 585 return GetProperty(proto, p);
555 } 586 }
556 587
557 588
558 // ES5 section 8.12.6 589 // ES5 section 8.12.6
559 function HasProperty(obj, p) { 590 function HasProperty(obj, p) {
591 if (%IsJSProxy(obj)) {
592 var handler = %GetHandler(obj)
593 var has = handler.has
594 if (IS_UNDEFINED(has)) has = DerivedHasTrap
595 return ToBoolean(has.call(handler, obj, p))
596 }
560 var desc = GetProperty(obj, p); 597 var desc = GetProperty(obj, p);
561 return IS_UNDEFINED(desc) ? false : true; 598 return IS_UNDEFINED(desc) ? false : true;
562 } 599 }
563 600
564 601
565 // ES5 section 8.12.1. 602 // ES5 section 8.12.1.
566 function GetOwnProperty(obj, p) { 603 function GetOwnProperty(obj, p) {
567 // GetOwnProperty returns an array indexed by the constants 604 // GetOwnProperty returns an array indexed by the constants
568 // defined in macros.py. 605 // defined in macros.py.
569 // If p is not a property on obj undefined is returned. 606 // If p is not a property on obj undefined is returned.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 775 }
739 } 776 }
740 return true; 777 return true;
741 } 778 }
742 779
743 780
744 // ES5 section 15.2.3.2. 781 // ES5 section 15.2.3.2.
745 function ObjectGetPrototypeOf(obj) { 782 function ObjectGetPrototypeOf(obj) {
746 if (!IS_SPEC_OBJECT(obj)) 783 if (!IS_SPEC_OBJECT(obj))
747 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); 784 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]);
748 return obj.__proto__; 785 return %GetPrototype(obj);
749 } 786 }
750 787
751 788
752 // ES5 section 15.2.3.3 789 // ES5 section 15.2.3.3
753 function ObjectGetOwnPropertyDescriptor(obj, p) { 790 function ObjectGetOwnPropertyDescriptor(obj, p) {
754 if (!IS_SPEC_OBJECT(obj)) 791 if (!IS_SPEC_OBJECT(obj))
755 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript or"]); 792 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript or"]);
756 var desc = GetOwnProperty(obj, p); 793 var desc = GetOwnProperty(obj, p);
757 return FromPropertyDescriptor(desc); 794 return FromPropertyDescriptor(desc);
758 } 795 }
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 // ---------------------------------------------------------------------------- 1351 // ----------------------------------------------------------------------------
1315 1352
1316 function SetupFunction() { 1353 function SetupFunction() {
1317 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1354 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1318 "bind", FunctionBind, 1355 "bind", FunctionBind,
1319 "toString", FunctionToString 1356 "toString", FunctionToString
1320 )); 1357 ));
1321 } 1358 }
1322 1359
1323 SetupFunction(); 1360 SetupFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698