| OLD | NEW |
| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (result != templates.end()) | 110 if (result != templates.end()) |
| 111 return result->value.newLocal(m_isolate); | 111 return result->value.newLocal(m_isolate); |
| 112 return v8::Local<v8::FunctionTemplate>(); | 112 return v8::Local<v8::FunctionTemplate>(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void V8PerIsolateData::setPrivateTemplate(WrapperWorldType currentWorldType, voi
d* privatePointer, v8::Handle<v8::FunctionTemplate> templ) | 115 void V8PerIsolateData::setPrivateTemplate(WrapperWorldType currentWorldType, voi
d* privatePointer, v8::Handle<v8::FunctionTemplate> templ) |
| 116 { | 116 { |
| 117 templateMap(currentWorldType).add(privatePointer, UnsafePersistent<v8::Funct
ionTemplate>(m_isolate, templ)); | 117 templateMap(currentWorldType).add(privatePointer, UnsafePersistent<v8::Funct
ionTemplate>(m_isolate, templ)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::rawDOMTemplate(const WrapperT
ypeInfo* info, WrapperWorldType currentWorldType) | |
| 121 { | |
| 122 TemplateMap& templates = rawDOMTemplateMap(currentWorldType); | |
| 123 TemplateMap::iterator result = templates.find(info); | |
| 124 if (result != templates.end()) | |
| 125 return result->value.newLocal(m_isolate); | |
| 126 | |
| 127 v8::EscapableHandleScope handleScope(m_isolate); | |
| 128 v8::Local<v8::FunctionTemplate> templ = createRawTemplate(m_isolate); | |
| 129 templates.add(info, UnsafePersistent<v8::FunctionTemplate>(m_isolate, templ)
); | |
| 130 return handleScope.Escape(templ); | |
| 131 } | |
| 132 | |
| 133 v8::Local<v8::Context> V8PerIsolateData::ensureRegexContext() | 120 v8::Local<v8::Context> V8PerIsolateData::ensureRegexContext() |
| 134 { | 121 { |
| 135 if (m_regexContext.isEmpty()) { | 122 if (m_regexContext.isEmpty()) { |
| 136 v8::HandleScope handleScope(m_isolate); | 123 v8::HandleScope handleScope(m_isolate); |
| 137 m_regexContext.set(m_isolate, v8::Context::New(m_isolate)); | 124 m_regexContext.set(m_isolate, v8::Context::New(m_isolate)); |
| 138 } | 125 } |
| 139 return m_regexContext.newLocal(m_isolate); | 126 return m_regexContext.newLocal(m_isolate); |
| 140 } | 127 } |
| 141 | 128 |
| 142 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V
alue> value, WrapperWorldType currentWorldType) | 129 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V
alue> value, WrapperWorldType currentWorldType) |
| 143 { | 130 { |
| 144 TemplateMap& templates = rawDOMTemplateMap(currentWorldType); | 131 TemplateMap& templates = templateMap(currentWorldType); |
| 145 TemplateMap::iterator result = templates.find(info); | 132 TemplateMap::iterator result = templates.find(info); |
| 146 if (result == templates.end()) | 133 if (result == templates.end()) |
| 147 return false; | 134 return false; |
| 148 v8::HandleScope handleScope(m_isolate); | 135 v8::HandleScope handleScope(m_isolate); |
| 149 return result->value.newLocal(m_isolate)->HasInstance(value); | 136 return result->value.newLocal(m_isolate)->HasInstance(value); |
| 150 } | 137 } |
| 151 | 138 |
| 152 void V8PerIsolateData::constructorOfToString(const v8::FunctionCallbackInfo<v8::
Value>& info) | 139 void V8PerIsolateData::constructorOfToString(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 153 { | 140 { |
| 154 // The DOM constructors' toString functions grab the current toString | 141 // The DOM constructors' toString functions grab the current toString |
| 155 // for Functions by taking the toString function of itself and then | 142 // for Functions by taking the toString function of itself and then |
| 156 // calling it with the constructor as its receiver. This means that | 143 // calling it with the constructor as its receiver. This means that |
| 157 // changes to the Function prototype chain or toString function are | 144 // changes to the Function prototype chain or toString function are |
| 158 // reflected when printing DOM constructors. The only wart is that | 145 // reflected when printing DOM constructors. The only wart is that |
| 159 // changes to a DOM constructor's toString's toString will cause the | 146 // changes to a DOM constructor's toString's toString will cause the |
| 160 // toString of the DOM constructor itself to change. This is extremely | 147 // toString of the DOM constructor itself to change. This is extremely |
| 161 // obscure and unlikely to be a problem. | 148 // obscure and unlikely to be a problem. |
| 162 v8::Handle<v8::Value> value = info.Callee()->Get(v8AtomicString(info.GetIsol
ate(), "toString")); | 149 v8::Handle<v8::Value> value = info.Callee()->Get(v8AtomicString(info.GetIsol
ate(), "toString")); |
| 163 if (!value->IsFunction()) { | 150 if (!value->IsFunction()) { |
| 164 v8SetReturnValue(info, v8::String::Empty(info.GetIsolate())); | 151 v8SetReturnValue(info, v8::String::Empty(info.GetIsolate())); |
| 165 return; | 152 return; |
| 166 } | 153 } |
| 167 v8SetReturnValue(info, V8ScriptRunner::callInternalFunction(v8::Handle<v8::F
unction>::Cast(value), info.This(), 0, 0, v8::Isolate::GetCurrent())); | 154 v8SetReturnValue(info, V8ScriptRunner::callInternalFunction(v8::Handle<v8::F
unction>::Cast(value), info.This(), 0, 0, v8::Isolate::GetCurrent())); |
| 168 } | 155 } |
| 169 | 156 |
| 170 } // namespace WebCore | 157 } // namespace WebCore |
| OLD | NEW |