~ubuntu-branches/ubuntu/saucy/nodejs/saucy-proposed

« back to all changes in this revision

Viewing changes to deps/v8/src/proxy.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
 
 
28
"use strict";
 
29
 
28
30
global.Proxy = new $Object();
29
31
 
30
32
var $Proxy = global.Proxy
32
34
$Proxy.create = function(handler, proto) {
33
35
  if (!IS_SPEC_OBJECT(handler))
34
36
    throw MakeTypeError("handler_non_object", ["create"])
35
 
  if (!IS_SPEC_OBJECT(proto)) proto = null  // Mozilla does this...
 
37
  if (IS_UNDEFINED(proto))
 
38
    proto = null
 
39
  else if (!(IS_SPEC_OBJECT(proto) || proto === null))
 
40
    throw MakeTypeError("proto_non_object", ["create"])
36
41
  return %CreateJSProxy(handler, proto)
37
42
}
38
43
 
42
47
  if (!IS_SPEC_FUNCTION(callTrap))
43
48
    throw MakeTypeError("trap_function_expected", ["createFunction", "call"])
44
49
  if (IS_UNDEFINED(constructTrap)) {
45
 
    constructTrap = callTrap
46
 
  } else if (!IS_SPEC_FUNCTION(constructTrap)) {
 
50
    constructTrap = DerivedConstructTrap(callTrap)
 
51
  } else if (IS_SPEC_FUNCTION(constructTrap)) {
 
52
    // Make sure the trap receives 'undefined' as this.
 
53
    var construct = constructTrap
 
54
    constructTrap = function() {
 
55
      return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength());
 
56
    }
 
57
  } else {
47
58
    throw MakeTypeError("trap_function_expected",
48
59
                        ["createFunction", "construct"])
49
60
  }
57
68
// Builtins
58
69
////////////////////////////////////////////////////////////////////////////////
59
70
 
 
71
function DerivedConstructTrap(callTrap) {
 
72
  return function() {
 
73
    var proto = this.prototype
 
74
    if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype
 
75
    var obj = new $Object()
 
76
    obj.__proto__ = proto
 
77
    var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength());
 
78
    return IS_SPEC_OBJECT(result) ? result : obj
 
79
  }
 
80
}
 
81
 
60
82
function DelegateCallAndConstruct(callTrap, constructTrap) {
61
83
  return function() {
62
84
    return %Apply(%_IsConstructCall() ? constructTrap : callTrap,
136
158
  var enumerableNames = []
137
159
  for (var i = 0, count = 0; i < names.length; ++i) {
138
160
    var name = names[i]
139
 
    if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) {
140
 
      enumerableNames[count++] = names[i]
141
 
    }
142
 
  }
143
 
  return enumerableNames
 
161
    var desc = this.getOwnPropertyDescriptor(TO_STRING_INLINE(name))
 
162
    if (!IS_UNDEFINED(desc) && desc.enumerable) {
 
163
      enumerableNames[count++] = names[i]
 
164
    }
 
165
  }
 
166
  return enumerableNames
 
167
}
 
168
 
 
169
function DerivedEnumerateTrap() {
 
170
  var names = this.getPropertyNames()
 
171
  var enumerableNames = []
 
172
  for (var i = 0, count = 0; i < names.length; ++i) {
 
173
    var name = names[i]
 
174
    var desc = this.getPropertyDescriptor(TO_STRING_INLINE(name))
 
175
    if (!IS_UNDEFINED(desc) && desc.enumerable) {
 
176
      enumerableNames[count++] = names[i]
 
177
    }
 
178
  }
 
179
  return enumerableNames
 
180
}
 
181
 
 
182
function ProxyEnumerate(proxy) {
 
183
  var handler = %GetHandler(proxy)
 
184
  if (IS_UNDEFINED(handler.enumerate)) {
 
185
    return %Apply(DerivedEnumerateTrap, handler, [], 0, 0)
 
186
  } else {
 
187
    return ToStringArray(handler.enumerate(), "enumerate")
 
188
  }
144
189
}