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

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

Issue 1417063011: [runtime] support new Proxy() instead of Proxy.create and install getPrototypeOf trap (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: adding proxy trap strings Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 var GlobalProxy = global.Proxy;
14 var GlobalFunction = global.Function; 14 var GlobalFunction = global.Function;
15 var GlobalObject = global.Object; 15 var GlobalObject = global.Object;
16 var MakeTypeError; 16 var MakeTypeError;
17 var ToNameArray; 17 var ToNameArray;
18 18
19 utils.Import(function(from) { 19 utils.Import(function(from) {
20 MakeTypeError = from.MakeTypeError; 20 MakeTypeError = from.MakeTypeError;
21 ToNameArray = from.ToNameArray; 21 ToNameArray = from.ToNameArray;
22 }); 22 });
23 23
24 //---------------------------------------------------------------------------- 24 //----------------------------------------------------------------------------
25 25
26 function ProxyCreate(handler, proto) { 26 function ProxyCreate(target, handler) {
27 if (!IS_SPEC_OBJECT(handler)) 27 if (!%_IsConstructCall()) {
28 throw MakeTypeError(kProxyHandlerNonObject, "create") 28 throw MakeTypeError(kConstructorNotFunction, "Proxy");
29 if (IS_UNDEFINED(proto)) 29 } else if (!IS_SPEC_OBJECT(target)) {
30 proto = null 30 throw MakeTypeError(kProxyTargetNonObject, "create")
31 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) 31 }
32 throw MakeTypeError(kProxyProtoNonObject) 32 if (IS_UNDEFINED(handler)) {
33 return %CreateJSProxy(handler, proto) 33 handler = null
34 } else if (!(IS_SPEC_OBJECT(handler) || IS_NULL(handler))) {
35 throw MakeTypeError(kProxyHandlerNonObject)
36 }
37 return %CreateJSProxy(target, handler)
34 } 38 }
35 39
36 function ProxyCreateFunction(handler, callTrap, constructTrap) { 40 function ProxyCreateFunction(handler, callTrap, constructTrap) {
37 if (!IS_SPEC_OBJECT(handler)) 41 if (!IS_SPEC_OBJECT(handler))
38 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") 42 throw MakeTypeError(kProxyTargetNonObject, "createFunction")
Jakob Kummerow 2015/11/12 12:04:24 This is surprising
Camillo Bruni 2015/11/12 20:20:55 blind rename :), reverting.
39 if (!IS_CALLABLE(callTrap)) 43 if (!IS_CALLABLE(callTrap))
40 throw MakeTypeError(kProxyTrapFunctionExpected, "call") 44 throw MakeTypeError(kProxyTrapFunctionExpected, "call")
41 if (IS_UNDEFINED(constructTrap)) { 45 if (IS_UNDEFINED(constructTrap)) {
42 constructTrap = DerivedConstructTrap(callTrap) 46 constructTrap = DerivedConstructTrap(callTrap)
43 } else if (IS_CALLABLE(constructTrap)) { 47 } else if (IS_CALLABLE(constructTrap)) {
44 // Make sure the trap receives 'undefined' as this. 48 // Make sure the trap receives 'undefined' as this.
45 var construct = constructTrap 49 var construct = constructTrap
46 constructTrap = function() { 50 constructTrap = function() {
47 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); 51 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength());
48 } 52 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 function ProxyEnumerate(proxy) { 179 function ProxyEnumerate(proxy) {
176 var handler = %GetHandler(proxy) 180 var handler = %GetHandler(proxy)
177 if (IS_UNDEFINED(handler.enumerate)) { 181 if (IS_UNDEFINED(handler.enumerate)) {
178 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) 182 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0)
179 } else { 183 } else {
180 return ToNameArray(handler.enumerate(), "enumerate", false) 184 return ToNameArray(handler.enumerate(), "enumerate", false)
181 } 185 }
182 } 186 }
183 187
184 //------------------------------------------------------------------- 188 //-------------------------------------------------------------------
189 %SetCode(GlobalProxy, ProxyCreate);
190 %FunctionSetPrototype(GlobalProxy, new GlobalObject());
185 191
186 var Proxy = new GlobalObject(); 192 // //Set up non-enumerable properties of the Proxy object.
187 %AddNamedProperty(global, "Proxy", Proxy, DONT_ENUM); 193 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [
194 "createFunction", ProxyCreateFunction
195 ]);
188 196
189 //Set up non-enumerable properties of the Proxy object. 197 %AddNamedProperty(GlobalProxy.prototype, "constructor", GlobalProxy, DONT_ENUM);
190 utils.InstallFunctions(Proxy, DONT_ENUM, [
191 "create", ProxyCreate,
192 "createFunction", ProxyCreateFunction
193 ])
194
195 // ------------------------------------------------------------------- 198 // -------------------------------------------------------------------
196 // Exports 199 // Exports
197 200
198 utils.Export(function(to) { 201 utils.Export(function(to) {
199 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; 202 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct;
200 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; 203 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap;
201 to.ProxyDerivedKeysTrap = DerivedKeysTrap; 204 to.ProxyDerivedKeysTrap = DerivedKeysTrap;
202 }); 205 });
203 206
204 %InstallToContext([ 207 %InstallToContext([
205 "derived_get_trap", DerivedGetTrap, 208 "derived_get_trap", DerivedGetTrap,
206 "derived_has_trap", DerivedHasTrap, 209 "derived_has_trap", DerivedHasTrap,
207 "derived_set_trap", DerivedSetTrap, 210 "derived_set_trap", DerivedSetTrap,
208 "proxy_enumerate", ProxyEnumerate, 211 "proxy_enumerate", ProxyEnumerate,
209 ]); 212 ]);
210 213
211 }) 214 })
OLDNEW
« no previous file with comments | « src/js/messages.js ('k') | src/messages.h » ('j') | src/messages.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698