natives-common.cc 1.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2015 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.

// The common functionality when building with internal or external natives.

#include "src/heap/heap.h"
#include "src/objects-inl.h"
#include "src/snapshot/natives.h"

namespace v8 {
namespace internal {

14 15 16 17
NativesExternalStringResource::NativesExternalStringResource(NativeType type,
                                                             int index)
    : type_(type), index_(index) {
  Vector<const char> source;
18
  DCHECK_LE(0, index);
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  switch (type_) {
    case CORE:
      DCHECK(index < Natives::GetBuiltinsCount());
      source = Natives::GetScriptSource(index);
      break;
    case EXTRAS:
      DCHECK(index < ExtraNatives::GetBuiltinsCount());
      source = ExtraNatives::GetScriptSource(index);
      break;
    case EXPERIMENTAL_EXTRAS:
      DCHECK(index < ExperimentalExtraNatives::GetBuiltinsCount());
      source = ExperimentalExtraNatives::GetScriptSource(index);
      break;
    default:
      UNREACHABLE();
  }
  data_ = source.start();
  length_ = source.length();
37 38
}

39 40
}  // namespace internal
}  // namespace v8