namespace blink {
-// Allocates new storage via fastMalloc.
-// Returns 0 if array failed to convert for any reason.
-static float* jsArrayToFloatArray(v8::Handle<v8::Array> array, uint32_t len, ExceptionState& exceptionState)
-{
- // Convert the data element-by-element.
- if (len > std::numeric_limits<uint32_t>::max() / sizeof(float)) {
- exceptionState.throwTypeError("Array length exceeds supported limit.");
- return 0;
- }
- float* data = static_cast<float*>(fastMalloc(len * sizeof(float)));
-
- for (uint32_t i = 0; i < len; i++) {
- v8::Local<v8::Value> val = array->Get(i);
- float value = toFloat(val, exceptionState);
- if (exceptionState.hadException()) {
- fastFree(data);
- return 0;
- }
- data[i] = value;
- }
- return data;
-}
-
-// Allocates new storage via fastMalloc.
-// Returns 0 if array failed to convert for any reason.
-static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len, ExceptionState& exceptionState)
-{
- // Convert the data element-by-element.
- if (len > std::numeric_limits<uint32_t>::max() / sizeof(int)) {
- exceptionState.throwTypeError("Array length exceeds supported limit.");
- return 0;
- }
- int* data = static_cast<int*>(fastMalloc(len * sizeof(int)));
-
- for (uint32_t i = 0; i < len; i++) {
- v8::Local<v8::Value> val = array->Get(i);
- int ival = toInt32(val, exceptionState);
- if (exceptionState.hadException()) {
- fastFree(data);
- return 0;
- }
- data[i] = ival;
- }
- return data;
-}
-
static v8::Handle<v8::Value> toV8Object(const WebGLGetInfo& args, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
switch (args.getType()) {
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
unsigned target;
unsigned pname;
{
static WebGLUniformLocation* toWebGLUniformLocation(v8::Handle<v8::Value> value, v8::Isolate* isolate)
{
- return V8WebGLUniformLocation::toNativeWithTypeCheck(isolate, value);
+ return V8WebGLUniformLocation::toImplWithTypeCheck(isolate, value);
}
void V8WebGLRenderingContext::getBufferParameterMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
void V8WebGLRenderingContext::getExtensionMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "getExtension", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
- WebGLRenderingContext* impl = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* impl = V8WebGLRenderingContext::toImpl(info.Holder());
if (info.Length() < 1) {
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
exceptionState.throwIfNeeded();
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
unsigned target;
unsigned attachment;
unsigned pname;
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
unsigned pname;
{
v8::TryCatch block;
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
WebGLProgram* program;
unsigned pname;
{
exceptionState.throwIfNeeded();
return;
}
- TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
+ TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toImplWithTypeCheck(info.GetIsolate(), info[0]));
TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exceptionState), exceptionState);
}
WebGLGetInfo args = context->getProgramParameter(program, pname);
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
WebGLShader* shader;
unsigned pname;
{
exceptionState.throwIfNeeded();
return;
}
- TONATIVE_VOID_INTERNAL(shader, V8WebGLShader::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
+ TONATIVE_VOID_INTERNAL(shader, V8WebGLShader::toImplWithTypeCheck(info.GetIsolate(), info[0]));
TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exceptionState), exceptionState);
}
WebGLGetInfo args = context->getShaderParameter(shader, pname);
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
WebGLProgram* program;
WebGLUniformLocation* location;
{
V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("getUniform", "WebGLRenderingContext", "parameter 1 is not of type 'WebGLProgram'."), info.GetIsolate());
return;
}
- TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
+ TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toImplWithTypeCheck(info.GetIsolate(), info[0]));
if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !V8WebGLUniformLocation::hasInstance(info[1], info.GetIsolate())) {
V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("getUniform", "WebGLRenderingContext", "parameter 2 is not of type 'WebGLUniformLocation'."), info.GetIsolate());
return;
}
- TONATIVE_VOID_INTERNAL(location, V8WebGLUniformLocation::toNativeWithTypeCheck(info.GetIsolate(), info[1]));
+ TONATIVE_VOID_INTERNAL(location, V8WebGLUniformLocation::toImplWithTypeCheck(info.GetIsolate(), info[1]));
}
WebGLGetInfo args = context->getUniform(program, location);
v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
location = toWebGLUniformLocation(info[uniformLocationArgumentIndex], info.GetIsolate());
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
const int indexArrayArgument = 1;
if (V8Float32Array::hasInstance(info[indexArrayArgument], info.GetIsolate())) {
- Float32Array* array = V8Float32Array::toNative(info[indexArrayArgument]->ToObject());
+ Float32Array* array = V8Float32Array::toImpl(info[indexArrayArgument]->ToObject());
ASSERT(array);
switch (functionToCall) {
case kUniform1v: context->uniform1fv(location, array); break;
return;
}
v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]);
- uint32_t len = array->Length();
- float* data = jsArrayToFloatArray(array, len, exceptionState);
- if (exceptionState.throwIfNeeded())
- return;
- if (!data) {
- // FIXME: consider different / better exception type.
- exceptionState.throwDOMException(SyntaxError, "Failed to convert array argument");
- exceptionState.throwIfNeeded();
+ if (array->Length() > WTF::DefaultAllocatorQuantizer::kMaxUnquantizedAllocation / sizeof(float)) {
+ exceptionState.throwTypeError("Array length exceeds supported limit.");
return;
}
+ Vector<float> implArray = toImplArray<float>(array, 0, info.GetIsolate(), exceptionState);
+ if (exceptionState.hadException())
+ return;
switch (functionToCall) {
- case kUniform1v: context->uniform1fv(location, data, len); break;
- case kUniform2v: context->uniform2fv(location, data, len); break;
- case kUniform3v: context->uniform3fv(location, data, len); break;
- case kUniform4v: context->uniform4fv(location, data, len); break;
- case kVertexAttrib1v: context->vertexAttrib1fv(index, data, len); break;
- case kVertexAttrib2v: context->vertexAttrib2fv(index, data, len); break;
- case kVertexAttrib3v: context->vertexAttrib3fv(index, data, len); break;
- case kVertexAttrib4v: context->vertexAttrib4fv(index, data, len); break;
+ case kUniform1v: context->uniform1fv(location, implArray.data(), implArray.size()); break;
+ case kUniform2v: context->uniform2fv(location, implArray.data(), implArray.size()); break;
+ case kUniform3v: context->uniform3fv(location, implArray.data(), implArray.size()); break;
+ case kUniform4v: context->uniform4fv(location, implArray.data(), implArray.size()); break;
+ case kVertexAttrib1v: context->vertexAttrib1fv(index, implArray.data(), implArray.size()); break;
+ case kVertexAttrib2v: context->vertexAttrib2fv(index, implArray.data(), implArray.size()); break;
+ case kVertexAttrib3v: context->vertexAttrib3fv(index, implArray.data(), implArray.size()); break;
+ case kVertexAttrib4v: context->vertexAttrib4fv(index, implArray.data(), implArray.size()); break;
default: ASSERT_NOT_REACHED(); break;
}
- fastFree(data);
}
static void uniformHelperi(const v8::FunctionCallbackInfo<v8::Value>& info, FunctionToCall functionToCall, ExceptionState& exceptionState)
}
const int uniformLocationArgumentIndex = 0;
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgumentIndex]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentIndex], info.GetIsolate())) {
exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrectType(uniformLocationArgumentIndex + 1, "WebGLUniformLocation"));
exceptionState.throwIfNeeded();
const int indexArrayArgumentIndex = 1;
if (V8Int32Array::hasInstance(info[indexArrayArgumentIndex], info.GetIsolate())) {
- Int32Array* array = V8Int32Array::toNative(info[indexArrayArgumentIndex]->ToObject());
+ Int32Array* array = V8Int32Array::toImpl(info[indexArrayArgumentIndex]->ToObject());
ASSERT(array);
switch (functionToCall) {
case kUniform1v: context->uniform1iv(location, array); break;
return;
}
v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[indexArrayArgumentIndex]);
- uint32_t len = array->Length();
- int* data = jsArrayToIntArray(array, len, exceptionState);
- if (exceptionState.throwIfNeeded())
- return;
- if (!data) {
- // FIXME: consider different / better exception type.
- exceptionState.throwDOMException(SyntaxError, "Failed to convert array argument");
- exceptionState.throwIfNeeded();
+ if (array->Length() > WTF::DefaultAllocatorQuantizer::kMaxUnquantizedAllocation / sizeof(int)) {
+ exceptionState.throwTypeError("Array length exceeds supported limit.");
return;
}
+ Vector<int> implArray = toImplArray<int>(array, 0, info.GetIsolate(), exceptionState);
+ if (exceptionState.hadException())
+ return;
switch (functionToCall) {
- case kUniform1v: context->uniform1iv(location, data, len); break;
- case kUniform2v: context->uniform2iv(location, data, len); break;
- case kUniform3v: context->uniform3iv(location, data, len); break;
- case kUniform4v: context->uniform4iv(location, data, len); break;
+ case kUniform1v: context->uniform1iv(location, implArray.data(), implArray.size()); break;
+ case kUniform2v: context->uniform2iv(location, implArray.data(), implArray.size()); break;
+ case kUniform3v: context->uniform3iv(location, implArray.data(), implArray.size()); break;
+ case kUniform4v: context->uniform4iv(location, implArray.data(), implArray.size()); break;
default: ASSERT_NOT_REACHED(); break;
}
- fastFree(data);
}
void V8WebGLRenderingContext::uniform1fvMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
return;
}
- WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Holder());
+ WebGLRenderingContext* context = V8WebGLRenderingContext::toImpl(info.Holder());
const int uniformLocationArgumentIndex = 0;
if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgumentIndex]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentIndex], info.GetIsolate())) {
bool transpose = info[1]->BooleanValue();
const int arrayArgumentIndex = 2;
if (V8Float32Array::hasInstance(info[arrayArgumentIndex], info.GetIsolate())) {
- Float32Array* array = V8Float32Array::toNative(info[arrayArgumentIndex]->ToObject());
+ Float32Array* array = V8Float32Array::toImpl(info[arrayArgumentIndex]->ToObject());
ASSERT(array);
switch (matrixSize) {
case 2: context->uniformMatrix2fv(location, transpose, array); break;
return;
}
v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[2]);
- uint32_t len = array->Length();
- float* data = jsArrayToFloatArray(array, len, exceptionState);
- if (exceptionState.throwIfNeeded())
- return;
- if (!data) {
- // FIXME: consider different / better exception type.
- exceptionState.throwDOMException(SyntaxError, "failed to convert Array value");
- exceptionState.throwIfNeeded();
+ if (array->Length() > WTF::DefaultAllocatorQuantizer::kMaxUnquantizedAllocation / sizeof(float)) {
+ exceptionState.throwTypeError("Array length exceeds supported limit.");
return;
}
+ Vector<float> implArray = toImplArray<float>(array, 0, info.GetIsolate(), exceptionState);
+ if (exceptionState.hadException())
+ return;
switch (matrixSize) {
- case 2: context->uniformMatrix2fv(location, transpose, data, len); break;
- case 3: context->uniformMatrix3fv(location, transpose, data, len); break;
- case 4: context->uniformMatrix4fv(location, transpose, data, len); break;
+ case 2: context->uniformMatrix2fv(location, transpose, implArray.data(), implArray.size()); break;
+ case 3: context->uniformMatrix3fv(location, transpose, implArray.data(), implArray.size()); break;
+ case 4: context->uniformMatrix4fv(location, transpose, implArray.data(), implArray.size()); break;
default: ASSERT_NOT_REACHED(); break;
}
- fastFree(data);
}
void V8WebGLRenderingContext::uniformMatrix2fvMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)