| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 return V8PerIsolateData::mainThreadIsolate(); | 828 return V8PerIsolateData::mainThreadIsolate(); |
| 829 return v8::Isolate::GetCurrent(); | 829 return v8::Isolate::GetCurrent(); |
| 830 } | 830 } |
| 831 | 831 |
| 832 v8::Isolate* toIsolate(LocalFrame* frame) | 832 v8::Isolate* toIsolate(LocalFrame* frame) |
| 833 { | 833 { |
| 834 ASSERT(frame); | 834 ASSERT(frame); |
| 835 return frame->script().isolate(); | 835 return frame->script().isolate(); |
| 836 } | 836 } |
| 837 | 837 |
| 838 PassRefPtr<JSONValue> v8ToJSONValue(v8::Isolate* isolate, v8::Handle<v8::Value>
value, int maxDepth) | 838 JSONValuePtr NativeValueTraits<JSONValuePtr>::nativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value, ExceptionState& exceptionState, int maxDepth) |
| 839 { | 839 { |
| 840 if (value.IsEmpty()) { | 840 if (value.IsEmpty()) { |
| 841 ASSERT_NOT_REACHED(); | 841 ASSERT_NOT_REACHED(); |
| 842 return nullptr; | 842 return nullptr; |
| 843 } | 843 } |
| 844 | 844 |
| 845 if (!maxDepth) | 845 if (!maxDepth) |
| 846 return nullptr; | 846 return nullptr; |
| 847 maxDepth--; | 847 maxDepth--; |
| 848 | 848 |
| 849 if (value->IsNull() || value->IsUndefined()) | 849 if (value->IsNull() || value->IsUndefined()) |
| 850 return JSONValue::null(); | 850 return JSONValue::null(); |
| 851 if (value->IsBoolean()) | 851 if (value->IsBoolean()) |
| 852 return JSONBasicValue::create(value->BooleanValue()); | 852 return JSONBasicValue::create(value->BooleanValue()); |
| 853 if (value->IsNumber()) | 853 if (value->IsNumber()) |
| 854 return JSONBasicValue::create(value->NumberValue()); | 854 return JSONBasicValue::create(value->NumberValue()); |
| 855 if (value->IsString()) | 855 if (value->IsString()) |
| 856 return JSONString::create(toCoreString(value.As<v8::String>())); | 856 return JSONString::create(toCoreString(value.As<v8::String>())); |
| 857 if (value->IsArray()) { | 857 if (value->IsArray()) { |
| 858 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); | 858 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); |
| 859 RefPtr<JSONArray> inspectorArray = JSONArray::create(); | 859 RefPtr<JSONArray> inspectorArray = JSONArray::create(); |
| 860 uint32_t length = array->Length(); | 860 uint32_t length = array->Length(); |
| 861 for (uint32_t i = 0; i < length; i++) { | 861 for (uint32_t i = 0; i < length; i++) { |
| 862 v8::Local<v8::Value> value = array->Get(v8::Int32::New(isolate, i)); | 862 v8::Local<v8::Value> value = array->Get(v8::Int32::New(isolate, i)); |
| 863 RefPtr<JSONValue> element = v8ToJSONValue(isolate, value, maxDepth); | 863 RefPtr<JSONValue> element = nativeValue(isolate, value, exceptionSta
te, maxDepth); |
| 864 if (!element) | 864 if (!element) |
| 865 return nullptr; | 865 return nullptr; |
| 866 inspectorArray->pushValue(element); | 866 inspectorArray->pushValue(element); |
| 867 } | 867 } |
| 868 return inspectorArray; | 868 return inspectorArray; |
| 869 } | 869 } |
| 870 if (value->IsObject()) { | 870 if (value->IsObject()) { |
| 871 RefPtr<JSONObject> jsonObject = JSONObject::create(); | 871 RefPtr<JSONObject> jsonObject = JSONObject::create(); |
| 872 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); | 872 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); |
| 873 v8::Local<v8::Array> propertyNames; | 873 v8::Local<v8::Array> propertyNames; |
| 874 if (!object->GetPropertyNames(isolate->GetCurrentContext()).ToLocal(&pro
pertyNames)) | 874 if (!object->GetPropertyNames(isolate->GetCurrentContext()).ToLocal(&pro
pertyNames)) |
| 875 return nullptr; | 875 return nullptr; |
| 876 uint32_t length = propertyNames->Length(); | 876 uint32_t length = propertyNames->Length(); |
| 877 for (uint32_t i = 0; i < length; i++) { | 877 for (uint32_t i = 0; i < length; i++) { |
| 878 v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(isolat
e, i)); | 878 v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(isolat
e, i)); |
| 879 // FIXME(yurys): v8::Object should support GetOwnPropertyNames | 879 // FIXME(yurys): v8::Object should support GetOwnPropertyNames |
| 880 if (name->IsString() && !object->HasRealNamedProperty(v8::Handle<v8:
:String>::Cast(name))) | 880 if (name->IsString() && !object->HasRealNamedProperty(v8::Handle<v8:
:String>::Cast(name))) |
| 881 continue; | 881 continue; |
| 882 RefPtr<JSONValue> propertyValue = v8ToJSONValue(isolate, object->Get
(name), maxDepth); | 882 RefPtr<JSONValue> propertyValue = nativeValue(isolate, object->Get(n
ame), exceptionState, maxDepth); |
| 883 if (!propertyValue) | 883 if (!propertyValue) |
| 884 return nullptr; | 884 return nullptr; |
| 885 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, nameString
, name, nullptr); | 885 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, nameString
, name, nullptr); |
| 886 jsonObject->setValue(nameString, propertyValue); | 886 jsonObject->setValue(nameString, propertyValue); |
| 887 } | 887 } |
| 888 return jsonObject; | 888 return jsonObject; |
| 889 } | 889 } |
| 890 ASSERT_NOT_REACHED(); | 890 ASSERT_NOT_REACHED(); |
| 891 return nullptr; | 891 return nullptr; |
| 892 } | 892 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 v8::Local<v8::Value> data = info.Data(); | 943 v8::Local<v8::Value> data = info.Data(); |
| 944 ASSERT(data->IsExternal()); | 944 ASSERT(data->IsExternal()); |
| 945 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre
ationContext()); | 945 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre
ationContext()); |
| 946 if (!perContextData) | 946 if (!perContextData) |
| 947 return; | 947 return; |
| 948 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u
nwrap(data))); | 948 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u
nwrap(data))); |
| 949 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); | 949 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); |
| 950 } | 950 } |
| 951 | 951 |
| 952 } // namespace blink | 952 } // namespace blink |
| OLD | NEW |