LCOV - code coverage report
Current view: top level - src/builtins - builtins-symbol.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 18 18 100.0 %
Date: 2017-04-26 Functions: 8 12 66.7 %

          Line data    Source code
       1             : // Copyright 2016 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             : #include "src/builtins/builtins-utils.h"
       6             : #include "src/builtins/builtins.h"
       7             : #include "src/counters.h"
       8             : #include "src/objects-inl.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : 
      13             : // -----------------------------------------------------------------------------
      14             : // ES6 section 19.4 Symbol Objects
      15             : 
      16             : // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case.
      17       17541 : BUILTIN(SymbolConstructor) {
      18             :   HandleScope scope(isolate);
      19        5847 :   Handle<Symbol> result = isolate->factory()->NewSymbol();
      20             :   Handle<Object> description = args.atOrUndefined(isolate, 1);
      21        5847 :   if (!description->IsUndefined(isolate)) {
      22        4770 :     ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description,
      23             :                                        Object::ToString(isolate, description));
      24        2371 :     result->set_name(*description);
      25             :   }
      26        5833 :   return *result;
      27             : }
      28             : 
      29             : // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case.
      30         300 : BUILTIN(SymbolConstructor_ConstructStub) {
      31             :   HandleScope scope(isolate);
      32         300 :   THROW_NEW_ERROR_RETURN_FAILURE(
      33             :       isolate, NewTypeError(MessageTemplate::kNotConstructor,
      34             :                             isolate->factory()->Symbol_string()));
      35             : }
      36             : 
      37             : // ES6 section 19.4.2.1 Symbol.for.
      38         609 : BUILTIN(SymbolFor) {
      39             :   HandleScope scope(isolate);
      40         203 :   Handle<Object> key_obj = args.atOrUndefined(isolate, 1);
      41             :   Handle<String> key;
      42         406 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
      43             :                                      Object::ToString(isolate, key_obj));
      44         406 :   return *isolate->SymbolFor(Heap::kPublicSymbolTableRootIndex, key, false);
      45             : }
      46             : 
      47             : // ES6 section 19.4.2.5 Symbol.keyFor.
      48         462 : BUILTIN(SymbolKeyFor) {
      49             :   HandleScope scope(isolate);
      50             :   Handle<Object> obj = args.atOrUndefined(isolate, 1);
      51         154 :   if (!obj->IsSymbol()) {
      52          56 :     THROW_NEW_ERROR_RETURN_FAILURE(
      53             :         isolate, NewTypeError(MessageTemplate::kSymbolKeyFor, obj));
      54             :   }
      55             :   Handle<Symbol> symbol = Handle<Symbol>::cast(obj);
      56             :   DisallowHeapAllocation no_gc;
      57             :   Object* result;
      58         126 :   if (symbol->is_public()) {
      59             :     result = symbol->name();
      60             :     DCHECK(result->IsString());
      61             :   } else {
      62          42 :     result = isolate->heap()->undefined_value();
      63             :   }
      64             :   DCHECK_EQ(isolate->heap()->public_symbol_table()->SlowReverseLookup(*symbol),
      65             :             result);
      66         126 :   return result;
      67             : }
      68             : 
      69             : }  // namespace internal
      70             : }  // namespace v8

Generated by: LCOV version 1.10