| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium 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 "platform/v8_inspector/V8InternalValueType.h" | |
| 6 | |
| 7 #include "platform/v8_inspector/ProtocolPlatform.h" | |
| 8 #include "platform/v8_inspector/StringUtil.h" | |
| 9 | |
| 10 namespace v8_inspector { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 v8::Local<v8::Private> internalSubtypePrivate(v8::Isolate* isolate) | |
| 15 { | |
| 16 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Inter
nalType#internalSubtype")); | |
| 17 } | |
| 18 | |
| 19 v8::Local<v8::String> subtypeForInternalType(v8::Isolate* isolate, V8InternalVal
ueType type) | |
| 20 { | |
| 21 switch (type) { | |
| 22 case V8InternalValueType::kEntry: | |
| 23 return toV8StringInternalized(isolate, "internal#entry"); | |
| 24 case V8InternalValueType::kLocation: | |
| 25 return toV8StringInternalized(isolate, "internal#location"); | |
| 26 case V8InternalValueType::kScope: | |
| 27 return toV8StringInternalized(isolate, "internal#scope"); | |
| 28 case V8InternalValueType::kScopeList: | |
| 29 return toV8StringInternalized(isolate, "internal#scopeList"); | |
| 30 } | |
| 31 NOTREACHED(); | |
| 32 return v8::Local<v8::String>(); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 bool markAsInternal(v8::Local<v8::Context> context, v8::Local<v8::Object> object
, V8InternalValueType type) | |
| 38 { | |
| 39 v8::Isolate* isolate = context->GetIsolate(); | |
| 40 v8::Local<v8::Private> privateValue = internalSubtypePrivate(isolate); | |
| 41 v8::Local<v8::String> subtype = subtypeForInternalType(isolate, type); | |
| 42 return object->SetPrivate(context, privateValue, subtype).FromMaybe(false); | |
| 43 } | |
| 44 | |
| 45 bool markArrayEntriesAsInternal(v8::Local<v8::Context> context, v8::Local<v8::Ar
ray> array, V8InternalValueType type) | |
| 46 { | |
| 47 v8::Isolate* isolate = context->GetIsolate(); | |
| 48 v8::Local<v8::Private> privateValue = internalSubtypePrivate(isolate); | |
| 49 v8::Local<v8::String> subtype = subtypeForInternalType(isolate, type); | |
| 50 for (size_t i = 0; i < array->Length(); ++i) { | |
| 51 v8::Local<v8::Value> entry; | |
| 52 if (!array->Get(context, i).ToLocal(&entry) || !entry->IsObject()) | |
| 53 return false; | |
| 54 if (!entry.As<v8::Object>()->SetPrivate(context, privateValue, subtype).
FromMaybe(false)) | |
| 55 return false; | |
| 56 } | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 v8::Local<v8::Value> v8InternalValueTypeFrom(v8::Local<v8::Context> context, v8:
:Local<v8::Object> object) | |
| 61 { | |
| 62 v8::Isolate* isolate = context->GetIsolate(); | |
| 63 v8::Local<v8::Private> privateValue = internalSubtypePrivate(isolate); | |
| 64 if (!object->HasPrivate(context, privateValue).FromMaybe(false)) | |
| 65 return v8::Null(isolate); | |
| 66 v8::Local<v8::Value> subtypeValue; | |
| 67 if (!object->GetPrivate(context, privateValue).ToLocal(&subtypeValue) || !su
btypeValue->IsString()) | |
| 68 return v8::Null(isolate); | |
| 69 return subtypeValue; | |
| 70 } | |
| 71 | |
| 72 } // namespace v8_inspector | |
| OLD | NEW |