blob: 842bac02525dfba5af65c4f753b4a9582ff74d00 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5(function(global, utils) {
6
7"use strict";
8
9%CheckIsBootstrapping();
10
11// ----------------------------------------------------------------------------
12// Imports
13//
14var GlobalProxy = global.Proxy;
15var MakeTypeError;
16
17utils.Import(function(from) {
18 MakeTypeError = from.MakeTypeError;
19});
20
21//----------------------------------------------------------------------------
22
23function ProxyCreateRevocable(target, handler) {
24 var p = new GlobalProxy(target, handler);
25 return {proxy: p, revoke: () => %JSProxyRevoke(p)};
26}
27
28// -------------------------------------------------------------------
29// Proxy Builtins
30
31// Implements part of ES6 9.5.11 Proxy.[[Enumerate]]:
32// Call the trap, which should return an iterator, exhaust the iterator,
33// and return an array containing the values.
34function ProxyEnumerate(trap, handler, target) {
35 // 7. Let trapResult be ? Call(trap, handler, «target»).
36 var trap_result = %_Call(trap, handler, target);
37 // 8. If Type(trapResult) is not Object, throw a TypeError exception.
38 if (!IS_RECEIVER(trap_result)) {
39 throw MakeTypeError(kProxyEnumerateNonObject);
40 }
41 // 9. Return trapResult.
42 var result = [];
43 for (var it = trap_result.next(); !it.done; it = trap_result.next()) {
44 var key = it.value;
45 // Not yet spec'ed as of 2015-11-25, but will be spec'ed soon:
46 // If the iterator returns a non-string value, throw a TypeError.
47 if (!IS_STRING(key)) {
48 throw MakeTypeError(kProxyEnumerateNonString);
49 }
50 result.push(key);
51 }
52 return result;
53}
54
55//-------------------------------------------------------------------
56
57//Set up non-enumerable properties of the Proxy object.
58utils.InstallFunctions(GlobalProxy, DONT_ENUM, [
59 "revocable", ProxyCreateRevocable
60]);
61
62// -------------------------------------------------------------------
63// Exports
64
65%InstallToContext([
66 "proxy_enumerate", ProxyEnumerate,
67]);
68
69})