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

Side by Side Diff: Source/bindings/core/v8/V8ValueCache.cpp

Issue 1097273002: Refactor core/v8/* methods to take isolate as first parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 48
49 StringCache::~StringCache() 49 StringCache::~StringCache()
50 { 50 {
51 // The MapType::Dispose callback calls StringCache::InvalidateLastString, 51 // The MapType::Dispose callback calls StringCache::InvalidateLastString,
52 // which will only work while the destructor has not yet finished. Thus, 52 // which will only work while the destructor has not yet finished. Thus,
53 // we need to clear the map before the destructor has completed. 53 // we need to clear the map before the destructor has completed.
54 m_stringCache.Clear(); 54 m_stringCache.Clear();
55 } 55 }
56 56
57 static v8::Local<v8::String> makeExternalString(const String& string, v8::Isolat e* isolate) 57 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri ng& string)
58 { 58 {
59 if (string.is8Bit()) { 59 if (string.is8Bit()) {
60 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri ng); 60 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri ng);
61 v8::Local<v8::String> newString; 61 v8::Local<v8::String> newString;
62 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne wString)) { 62 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne wString)) {
63 delete stringResource; 63 delete stringResource;
64 return v8::String::Empty(isolate); 64 return v8::String::Empty(isolate);
65 } 65 }
66 return newString; 66 return newString;
67 } 67 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 returnValue.Set(createStringAndInsertIntoCache(returnValue.GetIsolate(), str ingImpl)); 108 returnValue.Set(createStringAndInsertIntoCache(returnValue.GetIsolate(), str ingImpl));
109 } 109 }
110 110
111 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i solate, StringImpl* stringImpl) 111 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i solate, StringImpl* stringImpl)
112 { 112 {
113 ASSERT(!m_stringCache.Contains(stringImpl)); 113 ASSERT(!m_stringCache.Contains(stringImpl));
114 ASSERT(stringImpl->length()); 114 ASSERT(stringImpl->length());
115 115
116 v8::Local<v8::String> newString = makeExternalString(String(stringImpl), iso late); 116 v8::Local<v8::String> newString = makeExternalString(isolate, String(stringI mpl));
117 ASSERT(!newString.IsEmpty()); 117 ASSERT(!newString.IsEmpty());
118 ASSERT(newString->Length()); 118 ASSERT(newString->Length());
119 119
120 v8::UniquePersistent<v8::String> wrapper(isolate, newString); 120 v8::UniquePersistent<v8::String> wrapper(isolate, newString);
121 121
122 stringImpl->ref(); 122 stringImpl->ref();
123 wrapper.MarkIndependent(); 123 wrapper.MarkIndependent();
124 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); 124 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String);
125 m_lastStringImpl = stringImpl; 125 m_lastStringImpl = stringImpl;
126 126
127 return newString; 127 return newString;
128 } 128 }
129 129
130 void StringCache::InvalidateLastString() 130 void StringCache::InvalidateLastString()
131 { 131 {
132 m_lastStringImpl = nullptr; 132 m_lastStringImpl = nullptr;
133 m_lastV8String.Reset(); 133 m_lastV8String.Reset();
134 } 134 }
135 135
136 } // namespace blink 136 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8NPObject.cpp ('k') | Source/bindings/core/v8/custom/V8CSSStyleDeclarationCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698