Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: src/harmony-tostring.js

Issue 546803003: Update ObjectToString to Harmony-draft algorithm (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use intern'd strings instead of creating vectors Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 'use strict';
6
7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js and symbol.js:
9 // var $Object = global.Object;
10 // var $Symbol = global.Symbol;
11
12 var symbolToStringTag = InternalSymbol("Symbol.toStringTag");
13
14 var kBuiltinStringTags = {
15 "__proto__": null,
16 "Arguments": true,
17 "Array": true,
18 "Boolean": true,
19 "Date": true,
20 "Error": true,
21 "Function": true,
22 "Number": true,
23 "RegExp": true,
24 "String": true
25 };
26
27 // ES6 draft 08-24-14, section 19.1.3.6
28 function ObjectToStringHarmony() {
29 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
30 if (IS_NULL(this)) return "[object Null]";
31 var O = ToObject(this);
32 var builtinTag = %_ClassOf(O);
33 var tag = O[symbolToStringTag];
34 if (IS_UNDEFINED(tag)) {
35 tag = builtinTag;
36 } else if (!IS_STRING(tag)) {
37 return "[object ???]"
38 } else if (tag !== builtinTag && kBuiltinStringTags[tag]) {
39 return "[object ~" + tag + "]";
40 }
41 return "[object " + tag + "]";
42 }
43
44 function HarmonyToStringExtendSymbolPrototype() {
45 %CheckIsBootstrapping();
46
47 InstallConstants($Symbol, $Array(
48 // TODO: Move to symbol.js when shipping
49 "toStringTag", symbolToStringTag
50 ));
51 }
52
53 HarmonyToStringExtendSymbolPrototype();
54
55 function HarmonyToStringExtendObjectPrototype() {
56 %CheckIsBootstrapping();
57
58 // Set up the non-enumerable functions on the Array prototype object.
59 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
60 "toString", ObjectToStringHarmony
61 ));
62 }
63
64 HarmonyToStringExtendObjectPrototype();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698