Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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() | |
| 66 InstallFunctions($Proxy, DONT_ENUM, [ | |
| 67 "create", ProxyCreate, | |
| 68 "createFunction", ProxyCreateFunction | |
| 69 ]) | |
| 70 | |
| 71 | 69 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 73 // Builtins | 71 // Builtins |
| 74 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 75 | 73 |
| 76 function DerivedConstructTrap(callTrap) { | 74 function DerivedConstructTrap(callTrap) { |
| 77 return function() { | 75 return function() { |
| 78 var proto = this.prototype | 76 var proto = this.prototype |
| 79 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype | 77 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype |
| 80 var obj = { __proto__: proto }; | 78 var obj = { __proto__: proto }; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 } | 184 } |
| 187 | 185 |
| 188 function ProxyEnumerate(proxy) { | 186 function ProxyEnumerate(proxy) { |
| 189 var handler = %GetHandler(proxy) | 187 var handler = %GetHandler(proxy) |
| 190 if (IS_UNDEFINED(handler.enumerate)) { | 188 if (IS_UNDEFINED(handler.enumerate)) { |
| 191 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) | 189 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) |
| 192 } else { | 190 } else { |
| 193 return ToNameArray(handler.enumerate(), "enumerate", false) | 191 return ToNameArray(handler.enumerate(), "enumerate", false) |
| 194 } | 192 } |
| 195 } | 193 } |
| 194 | |
| 195 | |
| 196 // ------------------------------------------------------------------- | |
| 197 | |
| 198 function SetUpProxy() { | |
|
rossberg
2013/04/11 12:00:18
I don't like separating this from the method defin
Michael Starzinger
2013/04/11 12:08:44
Done (likewise for JSON).
| |
| 199 %CheckIsBootstrapping() | |
| 200 | |
| 201 global.Proxy = $Proxy; | |
| 202 | |
| 203 // Set up non-enumerable properties of the Proxy object. | |
| 204 InstallFunctions($Proxy, DONT_ENUM, [ | |
| 205 "create", ProxyCreate, | |
| 206 "createFunction", ProxyCreateFunction | |
| 207 ]) | |
| 208 } | |
| 209 | |
| 210 SetUpProxy(); | |
| OLD | NEW |