| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2011 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 bool ScriptValue::getString(String& result) const | 45 bool ScriptValue::getString(String& result) const |
| 46 { | 46 { |
| 47 if (hasNoValue()) | 47 if (hasNoValue()) |
| 48 return false; | 48 return false; |
| 49 | 49 |
| 50 v8::HandleScope handleScope(m_isolate); | 50 v8::HandleScope handleScope(m_isolate); |
| 51 v8::Handle<v8::Value> string = v8Value(); | 51 v8::Handle<v8::Value> string = v8Value(); |
| 52 if (string.IsEmpty() || !string->IsString()) | 52 if (string.IsEmpty() || !string->IsString()) |
| 53 return false; | 53 return false; |
| 54 result = toWebCoreString(string.As<v8::String>()); | 54 result = toCoreString(string.As<v8::String>()); |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 String ScriptValue::toString() const | 58 String ScriptValue::toString() const |
| 59 { | 59 { |
| 60 v8::TryCatch block; | 60 v8::TryCatch block; |
| 61 v8::Handle<v8::String> string = v8Value()->ToString(); | 61 v8::Handle<v8::String> string = v8Value()->ToString(); |
| 62 if (block.HasCaught()) | 62 if (block.HasCaught()) |
| 63 return String(); | 63 return String(); |
| 64 return v8StringToWebCoreString<String>(string, DoNotExternalize); | 64 return v8StringToWebCoreString<String>(string, DoNotExternalize); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 return 0; | 75 return 0; |
| 76 maxDepth--; | 76 maxDepth--; |
| 77 | 77 |
| 78 if (value->IsNull() || value->IsUndefined()) | 78 if (value->IsNull() || value->IsUndefined()) |
| 79 return JSONValue::null(); | 79 return JSONValue::null(); |
| 80 if (value->IsBoolean()) | 80 if (value->IsBoolean()) |
| 81 return JSONBasicValue::create(value->BooleanValue()); | 81 return JSONBasicValue::create(value->BooleanValue()); |
| 82 if (value->IsNumber()) | 82 if (value->IsNumber()) |
| 83 return JSONBasicValue::create(value->NumberValue()); | 83 return JSONBasicValue::create(value->NumberValue()); |
| 84 if (value->IsString()) | 84 if (value->IsString()) |
| 85 return JSONString::create(toWebCoreString(value.As<v8::String>())); | 85 return JSONString::create(toCoreString(value.As<v8::String>())); |
| 86 if (value->IsArray()) { | 86 if (value->IsArray()) { |
| 87 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); | 87 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); |
| 88 RefPtr<JSONArray> inspectorArray = JSONArray::create(); | 88 RefPtr<JSONArray> inspectorArray = JSONArray::create(); |
| 89 uint32_t length = array->Length(); | 89 uint32_t length = array->Length(); |
| 90 for (uint32_t i = 0; i < length; i++) { | 90 for (uint32_t i = 0; i < length; i++) { |
| 91 v8::Local<v8::Value> value = array->Get(v8::Int32::New(i, isolate)); | 91 v8::Local<v8::Value> value = array->Get(v8::Int32::New(i, isolate)); |
| 92 RefPtr<JSONValue> element = v8ToJSONValue(value, maxDepth, isolate); | 92 RefPtr<JSONValue> element = v8ToJSONValue(value, maxDepth, isolate); |
| 93 if (!element) | 93 if (!element) |
| 94 return 0; | 94 return 0; |
| 95 inspectorArray->pushValue(element); | 95 inspectorArray->pushValue(element); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 120 | 120 |
| 121 PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const | 121 PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const |
| 122 { | 122 { |
| 123 v8::HandleScope handleScope(scriptState->isolate()); | 123 v8::HandleScope handleScope(scriptState->isolate()); |
| 124 // v8::Object::GetPropertyNames() expects current context to be not null. | 124 // v8::Object::GetPropertyNames() expects current context to be not null. |
| 125 v8::Context::Scope contextScope(scriptState->context()); | 125 v8::Context::Scope contextScope(scriptState->context()); |
| 126 return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate())
; | 126 return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate())
; |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace WebCore | 129 } // namespace WebCore |
| OLD | NEW |