builtins-boolean.cc 1.31 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5
#include "src/builtins/builtins-utils-inl.h"
6
#include "src/builtins/builtins.h"
7 8
#include "src/counters.h"
#include "src/objects-inl.h"
9 10 11 12 13

namespace v8 {
namespace internal {

// -----------------------------------------------------------------------------
14
// ES #sec-boolean-objects
15

16
// ES #sec-boolean-constructor
17 18
BUILTIN(BooleanConstructor) {
  HandleScope scope(isolate);
19 20
  if (args.new_target()->IsUndefined(isolate)) {  // [[Call]]
    Handle<Object> value = args.atOrUndefined(isolate, 1);
21
    return isolate->heap()->ToBoolean(value->BooleanValue(isolate));
22
  }
23 24 25 26 27 28
  // [[Construct]]
  Handle<Object> value = args.atOrUndefined(isolate, 1);
  Handle<JSFunction> target = args.target();
  Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
  DCHECK(*target == target->native_context()->boolean_function());
  Handle<JSObject> result;
29 30 31
  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
      isolate, result,
      JSObject::New(target, new_target, Handle<AllocationSite>::null()));
32 33 34
  Handle<JSValue>::cast(result)->set_value(
      isolate->heap()->ToBoolean(value->BooleanValue(isolate)));
  return *result;
35 36 37 38
}

}  // namespace internal
}  // namespace v8