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

Side by Side Diff: src/proxy.js

Issue 1075773003: Wrap proxy.js in a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 5 years, 8 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
« no previous file with comments | « src/bootstrapper.cc ('k') | src/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 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 var $proxyDelegateCallAndConstruct;
6 var $proxyDerivedGetTrap;
7 var $proxyDerivedHasTrap;
8 var $proxyDerivedHasOwnTrap;
9 var $proxyDerivedKeysTrap;
10 var $proxyDerivedSetTrap;
11 var $proxyEnumerate;
12
13 (function() {
14
5 "use strict"; 15 "use strict";
rossberg 2015/04/10 11:00:28 DBC: is there a reason not to leave this at the to
Yang 2015/04/10 11:05:11 I'm considering the option of concatenating all (n
6 16
7 // This file relies on the fact that the following declaration has been made 17 %CheckIsBootstrapping();
8 // in runtime.js:
9 // var $Object = global.Object;
10 18
11 var $Proxy = new $Object(); 19 var GlobalObject = global.Object;
12 20
13 // ------------------------------------------------------------------- 21 // -------------------------------------------------------------------
14 22
15 function ProxyCreate(handler, proto) { 23 function ProxyCreate(handler, proto) {
16 if (!IS_SPEC_OBJECT(handler)) 24 if (!IS_SPEC_OBJECT(handler))
17 throw MakeTypeError("handler_non_object", ["create"]) 25 throw MakeTypeError("handler_non_object", ["create"])
18 if (IS_UNDEFINED(proto)) 26 if (IS_UNDEFINED(proto))
19 proto = null 27 proto = null
20 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) 28 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto)))
21 throw MakeTypeError("proto_non_object", ["create"]) 29 throw MakeTypeError("proto_non_object", ["create"])
(...skipping 14 matching lines...) Expand all
36 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); 44 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength());
37 } 45 }
38 } else { 46 } else {
39 throw MakeTypeError("trap_function_expected", 47 throw MakeTypeError("trap_function_expected",
40 ["createFunction", "construct"]) 48 ["createFunction", "construct"])
41 } 49 }
42 return %CreateJSFunctionProxy( 50 return %CreateJSFunctionProxy(
43 handler, callTrap, constructTrap, $Function.prototype) 51 handler, callTrap, constructTrap, $Function.prototype)
44 } 52 }
45 53
46
47 // -------------------------------------------------------------------
48
49 function SetUpProxy() {
50 %CheckIsBootstrapping()
51
52 var global_proxy = %GlobalProxy(global);
53 global_proxy.Proxy = $Proxy;
54
55 // Set up non-enumerable properties of the Proxy object.
56 InstallFunctions($Proxy, DONT_ENUM, [
57 "create", ProxyCreate,
58 "createFunction", ProxyCreateFunction
59 ])
60 }
61
62 SetUpProxy();
63
64
65 // ------------------------------------------------------------------- 54 // -------------------------------------------------------------------
66 // Proxy Builtins 55 // Proxy Builtins
67 56
68 function DerivedConstructTrap(callTrap) { 57 function DerivedConstructTrap(callTrap) {
69 return function() { 58 return function() {
70 var proto = this.prototype 59 var proto = this.prototype
71 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype 60 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype
72 var obj = { __proto__: proto }; 61 var obj = { __proto__: proto };
73 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); 62 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength());
74 return IS_SPEC_OBJECT(result) ? result : obj 63 return IS_SPEC_OBJECT(result) ? result : obj
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 171 }
183 172
184 function ProxyEnumerate(proxy) { 173 function ProxyEnumerate(proxy) {
185 var handler = %GetHandler(proxy) 174 var handler = %GetHandler(proxy)
186 if (IS_UNDEFINED(handler.enumerate)) { 175 if (IS_UNDEFINED(handler.enumerate)) {
187 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) 176 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0)
188 } else { 177 } else {
189 return ToNameArray(handler.enumerate(), "enumerate", false) 178 return ToNameArray(handler.enumerate(), "enumerate", false)
190 } 179 }
191 } 180 }
181
182 //-------------------------------------------------------------------
183
184 var Proxy = new GlobalObject();
185 %AddNamedProperty(global, "Proxy", Proxy, DONT_ENUM);
186
187 //Set up non-enumerable properties of the Proxy object.
188 InstallFunctions(Proxy, DONT_ENUM, [
189 "create", ProxyCreate,
190 "createFunction", ProxyCreateFunction
191 ])
192
193 $proxyDelegateCallAndConstruct = DelegateCallAndConstruct;
194 $proxyDerivedGetTrap = DerivedGetTrap;
195 $proxyDerivedHasTrap = DerivedHasTrap;
196 $proxyDerivedHasOwnTrap = DerivedHasOwnTrap;
197 $proxyDerivedKeysTrap = DerivedKeysTrap;
198 $proxyDerivedSetTrap = DerivedSetTrap;
199 $proxyEnumerate = ProxyEnumerate;
200
201 })();
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698