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

Side by Side Diff: src/js/proxy.js

Issue 1502593002: [API] GetOwnPropertyDescriptor: use C++ implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « src/js/array.js ('k') | src/js/v8natives.js » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ---------------------------------------------------------------------------- 11 // ----------------------------------------------------------------------------
12 // Imports 12 // Imports
13 // 13 //
14 var GlobalProxy = global.Proxy; 14 var GlobalProxy = global.Proxy;
15 var GlobalFunction = global.Function;
16 var GlobalObject = global.Object;
17 var MakeTypeError; 15 var MakeTypeError;
18 16
19 utils.Import(function(from) { 17 utils.Import(function(from) {
20 MakeTypeError = from.MakeTypeError; 18 MakeTypeError = from.MakeTypeError;
21 }); 19 });
22 20
23 //---------------------------------------------------------------------------- 21 //----------------------------------------------------------------------------
24 22
25 function ProxyCreateRevocable(target, handler) { 23 function ProxyCreateRevocable(target, handler) {
26 var p = new GlobalProxy(target, handler); 24 var p = new GlobalProxy(target, handler);
27 return {proxy: p, revoke: () => %RevokeProxy(p)}; 25 return {proxy: p, revoke: () => %RevokeProxy(p)};
28 } 26 }
29 27
30 // ------------------------------------------------------------------- 28 // -------------------------------------------------------------------
31 // Proxy Builtins 29 // Proxy Builtins
32 30
33 function DerivedConstructTrap(callTrap) {
34 return function() {
35 var proto = this.prototype
36 if (!IS_SPEC_OBJECT(proto)) proto = GlobalObject.prototype
37 var obj = { __proto__: proto };
38 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength());
39 return IS_SPEC_OBJECT(result) ? result : obj
40 }
41 }
42
43 function DelegateCallAndConstruct(callTrap, constructTrap) {
44 return function() {
45 return %Apply(IS_UNDEFINED(new.target) ? callTrap : constructTrap,
46 this, arguments, 0, %_ArgumentsLength())
47 }
48 }
49
50 function DerivedSetTrap(receiver, name, val) {
51 var desc = this.getOwnPropertyDescriptor(name)
52 if (desc) {
53 if ('writable' in desc) {
54 if (desc.writable) {
55 desc.value = val
56 this.defineProperty(name, desc)
57 return true
58 } else {
59 return false
60 }
61 } else { // accessor
62 if (desc.set) {
63 // The proposal says: desc.set.call(receiver, val)
64 %_Call(desc.set, receiver, val)
65 return true
66 } else {
67 return false
68 }
69 }
70 }
71 desc = this.getPropertyDescriptor(name)
72 if (desc) {
73 if ('writable' in desc) {
74 if (desc.writable) {
75 // fall through
76 } else {
77 return false
78 }
79 } else { // accessor
80 if (desc.set) {
81 // The proposal says: desc.set.call(receiver, val)
82 %_Call(desc.set, receiver, val)
83 return true
84 } else {
85 return false
86 }
87 }
88 }
89 this.defineProperty(name, {
90 value: val,
91 writable: true,
92 enumerable: true,
93 configurable: true});
94 return true;
95 }
96
97 function DerivedHasOwnTrap(name) {
98 return !!this.getOwnPropertyDescriptor(name)
99 }
100
101
102 // Implements part of ES6 9.5.11 Proxy.[[Enumerate]]: 31 // Implements part of ES6 9.5.11 Proxy.[[Enumerate]]:
103 // Call the trap, which should return an iterator, exhaust the iterator, 32 // Call the trap, which should return an iterator, exhaust the iterator,
104 // and return an array containing the values. 33 // and return an array containing the values.
105 function ProxyEnumerate(trap, handler, target) { 34 function ProxyEnumerate(trap, handler, target) {
106 // 7. Let trapResult be ? Call(trap, handler, «target»). 35 // 7. Let trapResult be ? Call(trap, handler, «target»).
107 var trap_result = %_Call(trap, handler, target); 36 var trap_result = %_Call(trap, handler, target);
108 // 8. If Type(trapResult) is not Object, throw a TypeError exception. 37 // 8. If Type(trapResult) is not Object, throw a TypeError exception.
109 if (!IS_SPEC_OBJECT(trap_result)) { 38 if (!IS_SPEC_OBJECT(trap_result)) {
110 throw MakeTypeError(kProxyHandlerReturned, handler, "non-Object", 39 throw MakeTypeError(kProxyHandlerReturned, handler, "non-Object",
111 "enumerate"); 40 "enumerate");
(...skipping 16 matching lines...) Expand all
128 //------------------------------------------------------------------- 57 //-------------------------------------------------------------------
129 58
130 //Set up non-enumerable properties of the Proxy object. 59 //Set up non-enumerable properties of the Proxy object.
131 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ 60 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [
132 "revocable", ProxyCreateRevocable 61 "revocable", ProxyCreateRevocable
133 ]); 62 ]);
134 63
135 // ------------------------------------------------------------------- 64 // -------------------------------------------------------------------
136 // Exports 65 // Exports
137 66
138 utils.Export(function(to) {
139 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct;
140 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap;
141 });
142
143 %InstallToContext([ 67 %InstallToContext([
144 "proxy_enumerate", ProxyEnumerate, 68 "proxy_enumerate", ProxyEnumerate,
145 ]); 69 ]);
146 70
147 }) 71 })
OLDNEW
« no previous file with comments | « src/js/array.js ('k') | src/js/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698