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

Side by Side Diff: src/proxy.js

Issue 14125004: Move global code for builtins into setup functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/math.js ('k') | src/regexp.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 // 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 "use strict"; 28 "use strict";
29 29
30 global.Proxy = new $Object(); 30 // This file relies on the fact that the following declaration has been made
31 // in runtime.js:
32 // var $Object = global.Object;
31 33
32 var $Proxy = global.Proxy 34 var $Proxy = new $Object();
35
36 // -------------------------------------------------------------------
33 37
34 function ProxyCreate(handler, proto) { 38 function ProxyCreate(handler, proto) {
35 if (!IS_SPEC_OBJECT(handler)) 39 if (!IS_SPEC_OBJECT(handler))
36 throw MakeTypeError("handler_non_object", ["create"]) 40 throw MakeTypeError("handler_non_object", ["create"])
37 if (IS_UNDEFINED(proto)) 41 if (IS_UNDEFINED(proto))
38 proto = null 42 proto = null
39 else if (!(IS_SPEC_OBJECT(proto) || proto === null)) 43 else if (!(IS_SPEC_OBJECT(proto) || proto === null))
40 throw MakeTypeError("proto_non_object", ["create"]) 44 throw MakeTypeError("proto_non_object", ["create"])
41 return %CreateJSProxy(handler, proto) 45 return %CreateJSProxy(handler, proto)
42 } 46 }
(...skipping 12 matching lines...) Expand all
55 return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength()); 59 return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength());
56 } 60 }
57 } else { 61 } else {
58 throw MakeTypeError("trap_function_expected", 62 throw MakeTypeError("trap_function_expected",
59 ["createFunction", "construct"]) 63 ["createFunction", "construct"])
60 } 64 }
61 return %CreateJSFunctionProxy( 65 return %CreateJSFunctionProxy(
62 handler, callTrap, constructTrap, $Function.prototype) 66 handler, callTrap, constructTrap, $Function.prototype)
63 } 67 }
64 68
65 %CheckIsBootstrapping() 69
66 InstallFunctions($Proxy, DONT_ENUM, [ 70 // -------------------------------------------------------------------
67 "create", ProxyCreate, 71
68 "createFunction", ProxyCreateFunction 72 function SetUpProxy() {
69 ]) 73 %CheckIsBootstrapping()
74
75 global.Proxy = $Proxy;
76
77 // Set up non-enumerable properties of the Proxy object.
78 InstallFunctions($Proxy, DONT_ENUM, [
79 "create", ProxyCreate,
80 "createFunction", ProxyCreateFunction
81 ])
82 }
83
84 SetUpProxy();
70 85
71 86
72 //////////////////////////////////////////////////////////////////////////////// 87 // -------------------------------------------------------------------
73 // Builtins 88 // Proxy Builtins
74 ////////////////////////////////////////////////////////////////////////////////
75 89
76 function DerivedConstructTrap(callTrap) { 90 function DerivedConstructTrap(callTrap) {
77 return function() { 91 return function() {
78 var proto = this.prototype 92 var proto = this.prototype
79 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype 93 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype
80 var obj = { __proto__: proto }; 94 var obj = { __proto__: proto };
81 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); 95 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength());
82 return IS_SPEC_OBJECT(result) ? result : obj 96 return IS_SPEC_OBJECT(result) ? result : obj
83 } 97 }
84 } 98 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 200 }
187 201
188 function ProxyEnumerate(proxy) { 202 function ProxyEnumerate(proxy) {
189 var handler = %GetHandler(proxy) 203 var handler = %GetHandler(proxy)
190 if (IS_UNDEFINED(handler.enumerate)) { 204 if (IS_UNDEFINED(handler.enumerate)) {
191 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) 205 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0)
192 } else { 206 } else {
193 return ToNameArray(handler.enumerate(), "enumerate", false) 207 return ToNameArray(handler.enumerate(), "enumerate", false)
194 } 208 }
195 } 209 }
OLDNEW
« no previous file with comments | « src/math.js ('k') | src/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698