summaryrefslogtreecommitdiffstats
path: root/src/proxy.js
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2012-04-12 10:51:47 +0100
committerBen Murdoch <benm@google.com>2012-04-16 16:41:38 +0100
commit3ef787dbeca8a5fb1086949cda830dccee07bfbd (patch)
tree0a22edd97aa148abffdd405c585b22213fccbc82 /src/proxy.js
parent85b71799222b55eb5dd74ea26efe0c64ab655c8c (diff)
downloadandroid_external_v8-3ef787dbeca8a5fb1086949cda830dccee07bfbd.tar.gz
android_external_v8-3ef787dbeca8a5fb1086949cda830dccee07bfbd.tar.bz2
android_external_v8-3ef787dbeca8a5fb1086949cda830dccee07bfbd.zip
Merge V8 at 3.9.24.13
Bug: 5688872 Change-Id: Id0aa8d23375030494d3189c31774059c0f5398fc
Diffstat (limited to 'src/proxy.js')
-rw-r--r--src/proxy.js53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/proxy.js b/src/proxy.js
index 4e44cd4e..4e86c889 100644
--- a/src/proxy.js
+++ b/src/proxy.js
@@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+"use strict";
+
global.Proxy = new $Object();
var $Proxy = global.Proxy
@@ -32,7 +34,10 @@ var $Proxy = global.Proxy
$Proxy.create = function(handler, proto) {
if (!IS_SPEC_OBJECT(handler))
throw MakeTypeError("handler_non_object", ["create"])
- if (!IS_SPEC_OBJECT(proto)) proto = null // Mozilla does this...
+ if (IS_UNDEFINED(proto))
+ proto = null
+ else if (!(IS_SPEC_OBJECT(proto) || proto === null))
+ throw MakeTypeError("proto_non_object", ["create"])
return %CreateJSProxy(handler, proto)
}
@@ -42,8 +47,14 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) {
if (!IS_SPEC_FUNCTION(callTrap))
throw MakeTypeError("trap_function_expected", ["createFunction", "call"])
if (IS_UNDEFINED(constructTrap)) {
- constructTrap = callTrap
- } else if (!IS_SPEC_FUNCTION(constructTrap)) {
+ constructTrap = DerivedConstructTrap(callTrap)
+ } else if (IS_SPEC_FUNCTION(constructTrap)) {
+ // Make sure the trap receives 'undefined' as this.
+ var construct = constructTrap
+ constructTrap = function() {
+ return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength());
+ }
+ } else {
throw MakeTypeError("trap_function_expected",
["createFunction", "construct"])
}
@@ -57,6 +68,17 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) {
// Builtins
////////////////////////////////////////////////////////////////////////////////
+function DerivedConstructTrap(callTrap) {
+ return function() {
+ var proto = this.prototype
+ if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype
+ var obj = new $Object()
+ obj.__proto__ = proto
+ var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength());
+ return IS_SPEC_OBJECT(result) ? result : obj
+ }
+}
+
function DelegateCallAndConstruct(callTrap, constructTrap) {
return function() {
return %Apply(%_IsConstructCall() ? constructTrap : callTrap,
@@ -136,9 +158,32 @@ function DerivedKeysTrap() {
var enumerableNames = []
for (var i = 0, count = 0; i < names.length; ++i) {
var name = names[i]
- if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) {
+ var desc = this.getOwnPropertyDescriptor(TO_STRING_INLINE(name))
+ if (!IS_UNDEFINED(desc) && desc.enumerable) {
+ enumerableNames[count++] = names[i]
+ }
+ }
+ return enumerableNames
+}
+
+function DerivedEnumerateTrap() {
+ var names = this.getPropertyNames()
+ var enumerableNames = []
+ for (var i = 0, count = 0; i < names.length; ++i) {
+ var name = names[i]
+ var desc = this.getPropertyDescriptor(TO_STRING_INLINE(name))
+ if (!IS_UNDEFINED(desc) && desc.enumerable) {
enumerableNames[count++] = names[i]
}
}
return enumerableNames
}
+
+function ProxyEnumerate(proxy) {
+ var handler = %GetHandler(proxy)
+ if (IS_UNDEFINED(handler.enumerate)) {
+ return %Apply(DerivedEnumerateTrap, handler, [], 0, 0)
+ } else {
+ return ToStringArray(handler.enumerate(), "enumerate")
+ }
+}