Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: Source/bindings/v8/ScriptValue.cpp

Issue 24139004: Add toWebCoreString() / toWebCoreAtomicString() overloads taking a v8::String (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix bad if condition Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/ScriptPreprocessor.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 bool ScriptValue::getString(String& result, v8::Isolate* isolate) const 65 bool ScriptValue::getString(String& result, v8::Isolate* isolate) const
66 { 66 {
67 if (hasNoValue()) 67 if (hasNoValue())
68 return false; 68 return false;
69 69
70 v8::HandleScope handleScope(isolate); 70 v8::HandleScope handleScope(isolate);
71 v8::Handle<v8::Value> string = v8Value(); 71 v8::Handle<v8::Value> string = v8Value();
72 if (string.IsEmpty() || !string->IsString()) 72 if (string.IsEmpty() || !string->IsString())
73 return false; 73 return false;
74 result = toWebCoreString(string); 74 result = toWebCoreString(string.As<v8::String>());
75 return true; 75 return true;
76 } 76 }
77 77
78 String ScriptValue::toString(ScriptState*) const 78 String ScriptValue::toString(ScriptState*) const
79 { 79 {
80 v8::TryCatch block; 80 v8::TryCatch block;
81 v8::Handle<v8::String> string = v8Value()->ToString(); 81 v8::Handle<v8::String> string = v8Value()->ToString();
82 if (block.HasCaught()) 82 if (block.HasCaught())
83 return String(); 83 return String();
84 return v8StringToWebCoreString<String>(string, DoNotExternalize); 84 return v8StringToWebCoreString<String>(string, DoNotExternalize);
(...skipping 10 matching lines...) Expand all
95 return 0; 95 return 0;
96 maxDepth--; 96 maxDepth--;
97 97
98 if (value->IsNull() || value->IsUndefined()) 98 if (value->IsNull() || value->IsUndefined())
99 return JSONValue::null(); 99 return JSONValue::null();
100 if (value->IsBoolean()) 100 if (value->IsBoolean())
101 return JSONBasicValue::create(value->BooleanValue()); 101 return JSONBasicValue::create(value->BooleanValue());
102 if (value->IsNumber()) 102 if (value->IsNumber())
103 return JSONBasicValue::create(value->NumberValue()); 103 return JSONBasicValue::create(value->NumberValue());
104 if (value->IsString()) 104 if (value->IsString())
105 return JSONString::create(toWebCoreString(value)); 105 return JSONString::create(toWebCoreString(value.As<v8::String>()));
106 if (value->IsArray()) { 106 if (value->IsArray()) {
107 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); 107 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
108 RefPtr<JSONArray> inspectorArray = JSONArray::create(); 108 RefPtr<JSONArray> inspectorArray = JSONArray::create();
109 uint32_t length = array->Length(); 109 uint32_t length = array->Length();
110 for (uint32_t i = 0; i < length; i++) { 110 for (uint32_t i = 0; i < length; i++) {
111 v8::Local<v8::Value> value = array->Get(v8::Int32::New(i, isolate)); 111 v8::Local<v8::Value> value = array->Get(v8::Int32::New(i, isolate));
112 RefPtr<JSONValue> element = v8ToJSONValue(value, maxDepth, isolate); 112 RefPtr<JSONValue> element = v8ToJSONValue(value, maxDepth, isolate);
113 if (!element) 113 if (!element)
114 return 0; 114 return 0;
115 inspectorArray->pushValue(element); 115 inspectorArray->pushValue(element);
(...skipping 23 matching lines...) Expand all
139 139
140 PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const 140 PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const
141 { 141 {
142 v8::HandleScope handleScope(scriptState->isolate()); 142 v8::HandleScope handleScope(scriptState->isolate());
143 // v8::Object::GetPropertyNames() expects current context to be not null. 143 // v8::Object::GetPropertyNames() expects current context to be not null.
144 v8::Context::Scope contextScope(scriptState->context()); 144 v8::Context::Scope contextScope(scriptState->context());
145 return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate()) ; 145 return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate()) ;
146 } 146 }
147 147
148 } // namespace WebCore 148 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptPreprocessor.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698