Commit 7667d19e authored by yangguo's avatar yangguo Committed by Commit bot

Wrap proxy.js in a function.

Review URL: https://codereview.chromium.org/1075773003

Cr-Commit-Position: refs/heads/master@{#27746}
parent c1f28b6c
......@@ -1572,10 +1572,10 @@ void Genesis::InstallNativeFunctions() {
void Genesis::InstallExperimentalNativeFunctions() {
if (FLAG_harmony_proxies) {
INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap);
INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap);
INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap);
INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate);
INSTALL_NATIVE(JSFunction, "$proxyDerivedHasTrap", derived_has_trap);
INSTALL_NATIVE(JSFunction, "$proxyDerivedGetTrap", derived_get_trap);
INSTALL_NATIVE(JSFunction, "$proxyDerivedSetTrap", derived_set_trap);
INSTALL_NATIVE(JSFunction, "$proxyEnumerate", proxy_enumerate);
}
#define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id();
......@@ -1662,10 +1662,10 @@ EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_spreadcalls)
void Genesis::InstallNativeFunctions_harmony_proxies() {
if (FLAG_harmony_proxies) {
INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap);
INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap);
INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap);
INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate);
INSTALL_NATIVE(JSFunction, "$proxyDerivedHasTrap", derived_has_trap);
INSTALL_NATIVE(JSFunction, "$proxyDerivedGetTrap", derived_get_trap);
INSTALL_NATIVE(JSFunction, "$proxyDerivedSetTrap", derived_set_trap);
INSTALL_NATIVE(JSFunction, "$proxyEnumerate", proxy_enumerate);
}
}
......
......@@ -2,13 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var $proxyDelegateCallAndConstruct;
var $proxyDerivedGetTrap;
var $proxyDerivedHasTrap;
var $proxyDerivedHasOwnTrap;
var $proxyDerivedKeysTrap;
var $proxyDerivedSetTrap;
var $proxyEnumerate;
(function() {
"use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Object = global.Object;
%CheckIsBootstrapping();
var $Proxy = new $Object();
var GlobalObject = global.Object;
// -------------------------------------------------------------------
......@@ -43,25 +51,6 @@ function ProxyCreateFunction(handler, callTrap, constructTrap) {
handler, callTrap, constructTrap, $Function.prototype)
}
// -------------------------------------------------------------------
function SetUpProxy() {
%CheckIsBootstrapping()
var global_proxy = %GlobalProxy(global);
global_proxy.Proxy = $Proxy;
// Set up non-enumerable properties of the Proxy object.
InstallFunctions($Proxy, DONT_ENUM, [
"create", ProxyCreate,
"createFunction", ProxyCreateFunction
])
}
SetUpProxy();
// -------------------------------------------------------------------
// Proxy Builtins
......@@ -189,3 +178,24 @@ function ProxyEnumerate(proxy) {
return ToNameArray(handler.enumerate(), "enumerate", false)
}
}
//-------------------------------------------------------------------
var Proxy = new GlobalObject();
%AddNamedProperty(global, "Proxy", Proxy, DONT_ENUM);
//Set up non-enumerable properties of the Proxy object.
InstallFunctions(Proxy, DONT_ENUM, [
"create", ProxyCreate,
"createFunction", ProxyCreateFunction
])
$proxyDelegateCallAndConstruct = DelegateCallAndConstruct;
$proxyDerivedGetTrap = DerivedGetTrap;
$proxyDerivedHasTrap = DerivedHasTrap;
$proxyDerivedHasOwnTrap = DerivedHasOwnTrap;
$proxyDerivedKeysTrap = DerivedKeysTrap;
$proxyDerivedSetTrap = DerivedSetTrap;
$proxyEnumerate = ProxyEnumerate;
})();
......@@ -266,7 +266,7 @@ function ObjectHasOwnProperty(V) {
if (IS_SYMBOL(V)) return false;
var handler = %GetHandler(this);
return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V));
return CallTrap1(handler, "hasOwn", $proxyDerivedHasOwnTrap, ToName(V));
}
return %HasOwnProperty(TO_OBJECT_INLINE(this), ToName(V));
}
......@@ -351,7 +351,7 @@ function ObjectKeys(obj) {
obj = TO_OBJECT_INLINE(obj);
if (%_IsJSProxy(obj)) {
var handler = %GetHandler(obj);
var names = CallTrap0(handler, "keys", DerivedKeysTrap);
var names = CallTrap0(handler, "keys", $proxyDerivedKeysTrap);
return ToNameArray(names, "keys", false);
}
return %OwnKeys(obj);
......@@ -1238,7 +1238,7 @@ function ProxyFix(obj) {
if (%IsJSFunctionProxy(obj)) {
var callTrap = %GetCallTrap(obj);
var constructTrap = %GetConstructTrap(obj);
var code = DelegateCallAndConstruct(callTrap, constructTrap);
var code = $proxyDelegateCallAndConstruct(callTrap, constructTrap);
%Fix(obj); // becomes a regular function
%SetCode(obj, code);
// TODO(rossberg): What about length and other properties? Not specified.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment