| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (prototypeString.IsEmpty()) | 82 if (prototypeString.IsEmpty()) |
| 83 return false; | 83 return false; |
| 84 | 84 |
| 85 V8_STORE_PRIMORDIAL(error, Error); | 85 V8_STORE_PRIMORDIAL(error, Error); |
| 86 | 86 |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 #undef V8_STORE_PRIMORDIAL | 90 #undef V8_STORE_PRIMORDIAL |
| 91 | 91 |
| 92 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(WrapperTy
peInfo* type) | 92 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) |
| 93 { | 93 { |
| 94 ASSERT(!m_errorPrototype.isEmpty()); | 94 ASSERT(!m_errorPrototype.isEmpty()); |
| 95 | 95 |
| 96 v8::Context::Scope scope(v8::Local<v8::Context>::New(m_isolate, m_context)); | 96 v8::Context::Scope scope(v8::Local<v8::Context>::New(m_isolate, m_context)); |
| 97 v8::Local<v8::Function> function = constructorForType(type); | 97 v8::Local<v8::Function> function = constructorForType(type); |
| 98 v8::Local<v8::Object> instance = V8ObjectConstructor::newInstance(function); | 98 v8::Local<v8::Object> instance = V8ObjectConstructor::newInstance(function); |
| 99 if (!instance.IsEmpty()) { | 99 if (!instance.IsEmpty()) { |
| 100 m_wrapperBoilerplates.set(type, UnsafePersistent<v8::Object>(m_isolate,
instance)); | 100 m_wrapperBoilerplates.set(type, UnsafePersistent<v8::Object>(m_isolate,
instance)); |
| 101 return instance->Clone(); | 101 return instance->Clone(); |
| 102 } | 102 } |
| 103 return v8::Local<v8::Object>(); | 103 return v8::Local<v8::Object>(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(WrapperType
Info* type) | 106 v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const Wrapp
erTypeInfo* type) |
| 107 { | 107 { |
| 108 ASSERT(!m_errorPrototype.isEmpty()); | 108 ASSERT(!m_errorPrototype.isEmpty()); |
| 109 | 109 |
| 110 v8::Context::Scope scope(v8::Local<v8::Context>::New(m_isolate, m_context)); | 110 v8::Context::Scope scope(v8::Local<v8::Context>::New(m_isolate, m_context)); |
| 111 v8::Handle<v8::FunctionTemplate> functionTemplate = type->getTemplate(m_isol
ate, worldType(m_isolate)); | 111 v8::Handle<v8::FunctionTemplate> functionTemplate = type->getTemplate(m_isol
ate, worldType(m_isolate)); |
| 112 // Getting the function might fail if we're running out of stack or memory. | 112 // Getting the function might fail if we're running out of stack or memory. |
| 113 v8::TryCatch tryCatch; | 113 v8::TryCatch tryCatch; |
| 114 v8::Local<v8::Function> function = functionTemplate->GetFunction(); | 114 v8::Local<v8::Function> function = functionTemplate->GetFunction(); |
| 115 if (function.IsEmpty()) | 115 if (function.IsEmpty()) |
| 116 return v8::Local<v8::Function>(); | 116 return v8::Local<v8::Function>(); |
| 117 | 117 |
| 118 if (type->parentClass) { | 118 if (type->parentClass) { |
| 119 v8::Local<v8::Object> proto = constructorForType(const_cast<WrapperTypeI
nfo*>(type->parentClass)); | 119 v8::Local<v8::Object> proto = constructorForType(type->parentClass); |
| 120 if (proto.IsEmpty()) | 120 if (proto.IsEmpty()) |
| 121 return v8::Local<v8::Function>(); | 121 return v8::Local<v8::Function>(); |
| 122 function->SetPrototype(proto); | 122 function->SetPrototype(proto); |
| 123 } | 123 } |
| 124 | 124 |
| 125 v8::Local<v8::Value> prototypeValue = function->Get(v8::String::NewSymbol("p
rototype")); | 125 v8::Local<v8::Value> prototypeValue = function->Get(v8::String::NewSymbol("p
rototype")); |
| 126 if (!prototypeValue.IsEmpty() && prototypeValue->IsObject()) { | 126 if (!prototypeValue.IsEmpty() && prototypeValue->IsObject()) { |
| 127 v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(prot
otypeValue); | 127 v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(prot
otypeValue); |
| 128 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcou
nt | 128 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcou
nt |
| 129 && type->wrapperTypePrototype == WrapperTypeObjectPrototype) | 129 && type->wrapperTypePrototype == WrapperTypeObjectPrototype) |
| 130 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd
ex, type); | 130 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd
ex, const_cast<WrapperTypeInfo*>(type)); |
| 131 type->installPerContextEnabledPrototypeProperties(prototypeObject, m_iso
late); | 131 type->installPerContextEnabledPrototypeProperties(prototypeObject, m_iso
late); |
| 132 if (type->wrapperTypePrototype == WrapperTypeErrorPrototype) | 132 if (type->wrapperTypePrototype == WrapperTypeErrorPrototype) |
| 133 prototypeObject->SetPrototype(m_errorPrototype.newLocal(m_isolate)); | 133 prototypeObject->SetPrototype(m_errorPrototype.newLocal(m_isolate)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 m_constructorMap.set(type, UnsafePersistent<v8::Function>(m_isolate, functio
n)); | 136 m_constructorMap.set(type, UnsafePersistent<v8::Function>(m_isolate, functio
n)); |
| 137 | 137 |
| 138 return function; | 138 return function; |
| 139 } | 139 } |
| 140 | 140 |
| 141 v8::Local<v8::Object> V8PerContextData::prototypeForType(WrapperTypeInfo* type) | 141 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo*
type) |
| 142 { | 142 { |
| 143 v8::Local<v8::Object> constructor = constructorForType(type); | 143 v8::Local<v8::Object> constructor = constructorForType(type); |
| 144 if (constructor.IsEmpty()) | 144 if (constructor.IsEmpty()) |
| 145 return v8::Local<v8::Object>(); | 145 return v8::Local<v8::Object>(); |
| 146 return constructor->Get(v8String("prototype", m_isolate)).As<v8::Object>(); | 146 return constructor->Get(v8String("prototype", m_isolate)).As<v8::Object>(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti
on, PassOwnPtr<CustomElementBinding> binding) | 149 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti
on, PassOwnPtr<CustomElementBinding> binding) |
| 150 { | 150 { |
| 151 ASSERT(!m_customElementBindings->contains(definition)); | 151 ASSERT(!m_customElementBindings->contains(definition)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (!data->IsString()) | 212 if (!data->IsString()) |
| 213 return -1; | 213 return -1; |
| 214 v8::String::AsciiValue ascii(data); | 214 v8::String::AsciiValue ascii(data); |
| 215 char* comma = strnstr(*ascii, ",", ascii.length()); | 215 char* comma = strnstr(*ascii, ",", ascii.length()); |
| 216 if (!comma) | 216 if (!comma) |
| 217 return -1; | 217 return -1; |
| 218 return atoi(comma + 1); | 218 return atoi(comma + 1); |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace WebCore | 221 } // namespace WebCore |
| OLD | NEW |