Home | History | Annotate | Download | only in results
      1 /*
      2     This file is part of the Blink open source project.
      3     This file has been auto-generated by CodeGeneratorV8.pm. DO NOT MODIFY!
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Library General Public
      7     License as published by the Free Software Foundation; either
      8     version 2 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Library General Public License for more details.
     14 
     15     You should have received a copy of the GNU Library General Public License
     16     along with this library; see the file COPYING.LIB.  If not, write to
     17     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     18     Boston, MA 02111-1307, USA.
     19 */
     20 
     21 #include "config.h"
     22 #include "V8Float64Array.h"
     23 
     24 #include "RuntimeEnabledFeatures.h"
     25 #include "V8ArrayBufferView.h"
     26 #include "bindings/v8/ExceptionState.h"
     27 #include "bindings/v8/ScriptController.h"
     28 #include "bindings/v8/V8Binding.h"
     29 #include "bindings/v8/V8DOMConfiguration.h"
     30 #include "bindings/v8/V8DOMWrapper.h"
     31 #include "bindings/v8/V8ObjectConstructor.h"
     32 #include "bindings/v8/custom/V8ArrayBufferCustom.h"
     33 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h"
     34 #include "bindings/v8/custom/V8Float32ArrayCustom.h"
     35 #include "bindings/v8/custom/V8Float64ArrayCustom.h"
     36 #include "bindings/v8/custom/V8Int32ArrayCustom.h"
     37 #include "core/dom/ContextFeatures.h"
     38 #include "core/dom/Document.h"
     39 #include "core/page/Frame.h"
     40 #include "core/platform/chromium/TraceEvent.h"
     41 #include "wtf/GetPtr.h"
     42 #include "wtf/RefPtr.h"
     43 #include "wtf/UnusedParam.h"
     44 
     45 namespace WebCore {
     46 
     47 static void initializeScriptWrappableForInterface(Float64Array* object)
     48 {
     49     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
     50         ScriptWrappable::setTypeInfoInObject(object, &V8Float64Array::info);
     51     else
     52         ASSERT_NOT_REACHED();
     53 }
     54 
     55 } // namespace WebCore
     56 
     57 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
     58 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
     59 // in the global namespace.
     60 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
     61 void webCoreInitializeScriptWrappableForInterface(Float64Array* object)
     62 {
     63     WebCore::initializeScriptWrappableForInterface(object);
     64 }
     65 
     66 namespace WebCore {
     67 WrapperTypeInfo V8Float64Array::info = { V8Float64Array::GetTemplate, V8Float64Array::derefObject, 0, 0, 0, V8Float64Array::installPerContextPrototypeProperties, &V8ArrayBufferView::info, WrapperTypeObjectPrototype };
     68 
     69 namespace Float64ArrayV8Internal {
     70 
     71 template <typename T> void V8_USE(T) { }
     72 
     73 static void fooMethod(const v8::FunctionCallbackInfo<v8::Value>& args)
     74 {
     75     if (args.Length() < 1) {
     76         throwNotEnoughArgumentsError(args.GetIsolate());
     77         return;
     78     }
     79     Float64Array* imp = V8Float64Array::toNative(args.Holder());
     80     V8TRYCATCH_VOID(Float32Array*, array, args[0]->IsFloat32Array() ? V8Float32Array::toNative(v8::Handle<v8::Float32Array>::Cast(args[0])) : 0);
     81     v8SetReturnValue(args, toV8(imp->foo(array), args.Holder(), args.GetIsolate()));
     82     return;
     83 }
     84 
     85 static void fooMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
     86 {
     87     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
     88     Float64ArrayV8Internal::fooMethod(args);
     89     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
     90 }
     91 
     92 static void setMethod(const v8::FunctionCallbackInfo<v8::Value>& args)
     93 {
     94     setWebGLArrayHelper<Float64Array, V8Float64Array>(args);
     95 }
     96 
     97 static void setMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
     98 {
     99     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
    100     Float64ArrayV8Internal::setMethod(args);
    101     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
    102 }
    103 
    104 static void indexedPropertyGetterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
    105 {
    106     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
    107     V8Float64Array::indexedPropertyGetterCustom(index, info);
    108     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
    109 }
    110 
    111 static void indexedPropertySetterCallback(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
    112 {
    113     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
    114     V8Float64Array::indexedPropertySetterCustom(index, value, info);
    115     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
    116 }
    117 
    118 } // namespace Float64ArrayV8Internal
    119 
    120 v8::Handle<v8::Object> wrap(Float64Array* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    121 {
    122     ASSERT(impl);
    123     v8::Handle<v8::Object> wrapper = V8Float64Array::createWrapper(impl, creationContext, isolate);
    124     if (!wrapper.IsEmpty())
    125         wrapper->SetIndexedPropertiesToExternalArrayData(impl->baseAddress(), v8::kExternalDoubleArray, impl->length());
    126     return wrapper;
    127 }
    128 
    129 static const V8DOMConfiguration::BatchedMethod V8Float64ArrayMethods[] = {
    130     {"set", Float64ArrayV8Internal::setMethodCallback, 0, 0},
    131 };
    132 
    133 void V8Float64Array::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
    134 {
    135     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
    136     if (!args.IsConstructCall()) {
    137         throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
    138         return;
    139     }
    140 
    141     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
    142         args.GetReturnValue().Set(args.Holder());
    143         return;
    144     }
    145 
    146     Float64ArrayV8Internal::constructor(args);
    147 }
    148 
    149 static v8::Handle<v8::FunctionTemplate> ConfigureV8Float64ArrayTemplate(v8::Handle<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    150 {
    151     desc->ReadOnlyPrototype();
    152 
    153     v8::Local<v8::Signature> defaultSignature;
    154     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "Float64Array", V8ArrayBufferView::GetTemplate(isolate, currentWorldType), V8Float64Array::internalFieldCount,
    155         0, 0,
    156         V8Float64ArrayMethods, WTF_ARRAY_LENGTH(V8Float64ArrayMethods), isolate, currentWorldType);
    157     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
    158     desc->SetCallHandler(V8Float64Array::constructorCallback);
    159     desc->SetLength(1);
    160     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
    161     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
    162     UNUSED_PARAM(instance); // In some cases, it will not be used.
    163     UNUSED_PARAM(proto); // In some cases, it will not be used.
    164     desc->InstanceTemplate()->SetIndexedPropertyHandler(Float64ArrayV8Internal::indexedPropertyGetterCallback, Float64ArrayV8Internal::indexedPropertySetterCallback, 0, 0, indexedPropertyEnumerator<Float64Array>);
    165 
    166     // Custom Signature 'foo'
    167     const int fooArgc = 1;
    168     v8::Handle<v8::FunctionTemplate> fooArgv[fooArgc] = { v8::Handle<v8::FunctionTemplate>() };
    169     v8::Handle<v8::Signature> fooSignature = v8::Signature::New(desc, fooArgc, fooArgv);
    170     proto->Set(v8::String::NewSymbol("foo"), v8::FunctionTemplate::New(Float64ArrayV8Internal::fooMethodCallback, v8Undefined(), fooSignature, 1));
    171 
    172     // Custom toString template
    173     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
    174     return desc;
    175 }
    176 
    177 v8::Handle<v8::FunctionTemplate> V8Float64Array::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
    178 {
    179     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    180     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&info);
    181     if (result != data->templateMap(currentWorldType).end())
    182         return result->value.newLocal(isolate);
    183 
    184     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
    185     v8::HandleScope handleScope(isolate);
    186     v8::Handle<v8::FunctionTemplate> templ =
    187         ConfigureV8Float64ArrayTemplate(data->rawTemplate(&info, currentWorldType), isolate, currentWorldType);
    188     data->templateMap(currentWorldType).add(&info, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
    189     return handleScope.Close(templ);
    190 }
    191 
    192 bool V8Float64Array::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    193 {
    194     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWorldType);
    195 }
    196 
    197 bool V8Float64Array::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate* isolate)
    198 {
    199     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld)
    200         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWorld)
    201         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorld);
    202 }
    203 
    204 
    205 v8::Handle<v8::Object> V8Float64Array::createWrapper(PassRefPtr<Float64Array> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    206 {
    207     ASSERT(impl.get());
    208     ASSERT(DOMDataStore::getWrapper<V8Float64Array>(impl.get(), isolate).IsEmpty());
    209     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
    210         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
    211         // Might be a XXXConstructor::info instead of an XXX::info. These will both have
    212         // the same object de-ref functions, though, so use that as the basis of the check.
    213         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == info.derefObjectFunction);
    214     }
    215 
    216 
    217     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, toInternalPointer(impl.get()), isolate);
    218     if (UNLIKELY(wrapper.IsEmpty()))
    219         return wrapper;
    220     if (!impl->buffer()->hasDeallocationObserver()) {
    221         v8::V8::AdjustAmountOfExternalAllocatedMemory(impl->buffer()->byteLength());
    222         impl->buffer()->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
    223     }
    224     installPerContextProperties(wrapper, impl.get(), isolate);
    225     V8DOMWrapper::associateObjectWithWrapper<V8Float64Array>(impl, &info, wrapper, isolate, WrapperConfiguration::Independent);
    226     return wrapper;
    227 }
    228 void V8Float64Array::derefObject(void* object)
    229 {
    230     fromInternalPointer(object)->deref();
    231 }
    232 
    233 } // namespace WebCore
    234