// Copyright 2013 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.

'use strict';

// This file relies on the fact that the following declaration has been made
// in runtime.js and symbol.js:
// var $Object = global.Object;
// var $Symbol = global.Symbol;

var symbolToStringTag = InternalSymbol("Symbol.toStringTag");

var kBuiltinStringTags = {
  "__proto__": null,
  "Arguments": true,
  "Array": true,
  "Boolean": true,
  "Date": true,
  "Error": true,
  "Function": true,
  "Number": true,
  "RegExp": true,
  "String": true
};

DefaultObjectToString = ObjectToStringHarmony;
// ES6 draft 08-24-14, section 19.1.3.6
function ObjectToStringHarmony() {
  if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
  if (IS_NULL(this)) return "[object Null]";
  var O = ToObject(this);
  var builtinTag = %_ClassOf(O);
  var tag = O[symbolToStringTag];
  if (IS_UNDEFINED(tag)) {
    tag = builtinTag;
  } else if (!IS_STRING(tag)) {
    return "[object ???]"
  } else if (tag !== builtinTag && kBuiltinStringTags[tag]) {
    return "[object ~" + tag + "]";
  }
  return "[object " + tag + "]";
}

function HarmonyToStringExtendSymbolPrototype() {
  %CheckIsBootstrapping();

  InstallConstants($Symbol, $Array(
    // TODO(dslomov, caitp): Move to symbol.js when shipping
   "toStringTag", symbolToStringTag
  ));
}

HarmonyToStringExtendSymbolPrototype();

function HarmonyToStringExtendObjectPrototype() {
  %CheckIsBootstrapping();

  // Set up the non-enumerable functions on the Array prototype object.
  var desc = ToPropertyDescriptor({
    value: ObjectToStringHarmony
  });
  DefineOwnProperty($Object.prototype, "toString", desc, false);
}

HarmonyToStringExtendObjectPrototype();

@@ -1553,16 +1553,269 @@
 ing();%0A%0A
+  // Can't use InstallFunctions() because will fail in Debug mode.%0A  // Emulate InstallFunctions() here.%0A  %25FunctionSetName(ObjectToStringHarmony, %22toString%22);%0A  %25FunctionRemovePrototype(ObjectToStringHarmony);%0A  %25SetNativeFlag(ObjectToStringHarmony);%0A%0A
   // Set
@@ -2017,16 +2017,57 @@
  false);
+%0A%0A  %25ToFastProperties($Object.prototype);
 %0A%7D%0A%0AHarm

Remove [[PROTOTYPE]] from ObjectToStringHarmony