summaryrefslogtreecommitdiff
path: root/deps/v8/src/js/v8natives.js
blob: 26dada3759be47a8ebfa277d9e3f0c2242523f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

(function(global, utils) {

"use strict";

%CheckIsBootstrapping();

// ----------------------------------------------------------------------------
// Imports

var GlobalObject = global.Object;
var iteratorSymbol = utils.ImportNow("iterator_symbol");

// ----------------------------------------------------------------------------
// Object

// Set up non-enumerable functions on the Object.prototype object.
DEFINE_METHOD(
  GlobalObject.prototype,
  // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]])
  toLocaleString() {
    REQUIRE_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString");
    return this.toString();
  }
);

// ES6 7.3.9
function GetMethod(obj, p) {
  var func = obj[p];
  if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED;
  if (IS_CALLABLE(func)) return func;
  throw %make_type_error(kCalledNonCallable, typeof func);
}

// ----------------------------------------------------------------------------
// Iterator related spec functions.

// ES6 7.4.1 GetIterator(obj, method)
function GetIterator(obj, method) {
  if (IS_UNDEFINED(method)) {
    method = obj[iteratorSymbol];
  }
  if (!IS_CALLABLE(method)) {
    throw %make_type_error(kNotIterable, obj);
  }
  var iterator = %_Call(method, obj);
  if (!IS_RECEIVER(iterator)) {
    throw %make_type_error(kNotAnIterator, iterator);
  }
  return iterator;
}

// ----------------------------------------------------------------------------
// Exports

utils.Export(function(to) {
  to.GetIterator = GetIterator;
  to.GetMethod = GetMethod;
});

})