• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2014 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// Flags: --expose-debug-as debug --harmony-symbols
6// Test the mirror object for symbols.
7
8function testSymbolMirror(symbol, description) {
9  // Create mirror and JSON representation.
10  var mirror = debug.MakeMirror(symbol);
11  var serializer = debug.MakeMirrorSerializer();
12  var json = JSON.stringify(serializer.serializeValue(mirror));
13
14  // Check the mirror hierachy.
15  assertTrue(mirror instanceof debug.Mirror);
16  assertTrue(mirror instanceof debug.ValueMirror);
17  assertTrue(mirror instanceof debug.SymbolMirror);
18
19  // Check the mirror properties.
20  assertTrue(mirror.isSymbol());
21  assertEquals(description, mirror.description());
22  assertEquals('symbol', mirror.type());
23  assertTrue(mirror.isPrimitive());
24  var description_text = description === undefined ? "" : description;
25  assertEquals('Symbol(' + description_text + ')', mirror.toText());
26  assertSame(symbol, mirror.value());
27
28  // Parse JSON representation and check.
29  var fromJSON = eval('(' + json + ')');
30  assertEquals('symbol', fromJSON.type);
31  assertEquals(description, fromJSON.description);
32}
33
34// Test a number of different symbols.
35testSymbolMirror(Symbol("a"), "a");
36testSymbolMirror(Symbol(12), "12");
37testSymbolMirror(Symbol.for("b"), "b");
38testSymbolMirror(Symbol(), undefined);
39