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 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 #include "core/dom/ExceptionCode.h" | 75 #include "core/dom/ExceptionCode.h" |
76 #include "core/html/canvas/WebGLRenderingContext.h" | 76 #include "core/html/canvas/WebGLRenderingContext.h" |
77 #include "platform/NotImplemented.h" | 77 #include "platform/NotImplemented.h" |
78 #include "wtf/FastMalloc.h" | 78 #include "wtf/FastMalloc.h" |
79 #include <limits> | 79 #include <limits> |
80 | 80 |
81 namespace WebCore { | 81 namespace WebCore { |
82 | 82 |
83 // Allocates new storage via fastMalloc. | 83 // Allocates new storage via fastMalloc. |
84 // Returns NULL if array failed to convert for any reason. | 84 // Returns NULL if array failed to convert for any reason. |
85 static float* jsArrayToFloatArray(v8::Handle<v8::Array> array, uint32_t len) | 85 static float* jsArrayToFloatArray(v8::Handle<v8::Array> array, uint32_t len, Exc
eptionState& exceptionState) |
86 { | 86 { |
87 // Convert the data element-by-element. | 87 // Convert the data element-by-element. |
88 if (len > std::numeric_limits<uint32_t>::max() / sizeof(float)) | 88 if (len > std::numeric_limits<uint32_t>::max() / sizeof(float)) { |
| 89 exceptionState.throwTypeError("Array length exceeds supported limit."); |
89 return 0; | 90 return 0; |
| 91 } |
90 float* data = static_cast<float*>(fastMalloc(len * sizeof(float))); | 92 float* data = static_cast<float*>(fastMalloc(len * sizeof(float))); |
91 | 93 |
92 for (uint32_t i = 0; i < len; i++) { | 94 for (uint32_t i = 0; i < len; i++) { |
93 v8::Local<v8::Value> val = array->Get(i); | 95 v8::Local<v8::Value> val = array->Get(i); |
94 if (!val->IsNumber()) { | 96 float value = toFloat(val, exceptionState); |
| 97 if (exceptionState.hadException()) { |
95 fastFree(data); | 98 fastFree(data); |
96 return 0; | 99 return 0; |
97 } | 100 } |
98 data[i] = toFloat(val); | 101 data[i] = value; |
99 } | 102 } |
100 return data; | 103 return data; |
101 } | 104 } |
102 | 105 |
103 // Allocates new storage via fastMalloc. | 106 // Allocates new storage via fastMalloc. |
104 // Returns NULL if array failed to convert for any reason. | 107 // Returns NULL if array failed to convert for any reason. |
105 static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len) | 108 static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len, Excepti
onState& exceptionState) |
106 { | 109 { |
107 // Convert the data element-by-element. | 110 // Convert the data element-by-element. |
108 if (len > std::numeric_limits<uint32_t>::max() / sizeof(int)) | 111 if (len > std::numeric_limits<uint32_t>::max() / sizeof(int)) { |
| 112 exceptionState.throwTypeError("Array length exceeds supported limit."); |
109 return 0; | 113 return 0; |
| 114 } |
110 int* data = static_cast<int*>(fastMalloc(len * sizeof(int))); | 115 int* data = static_cast<int*>(fastMalloc(len * sizeof(int))); |
111 | 116 |
112 for (uint32_t i = 0; i < len; i++) { | 117 for (uint32_t i = 0; i < len; i++) { |
113 v8::Local<v8::Value> val = array->Get(i); | 118 v8::Local<v8::Value> val = array->Get(i); |
114 bool ok; | 119 int ival = toInt32(val, exceptionState); |
115 int ival = toInt32(val, ok); | 120 if (exceptionState.hadException()) { |
116 if (!ok) { | |
117 fastFree(data); | 121 fastFree(data); |
118 return 0; | 122 return 0; |
119 } | 123 } |
120 data[i] = ival; | 124 data[i] = ival; |
121 } | 125 } |
122 return data; | 126 return data; |
123 } | 127 } |
124 | 128 |
125 static v8::Handle<v8::Value> toV8Object(const WebGLGetInfo& args, v8::Handle<v8:
:Object> creationContext, v8::Isolate* isolate) | 129 static v8::Handle<v8::Value> toV8Object(const WebGLGetInfo& args, v8::Handle<v8:
:Object> creationContext, v8::Isolate* isolate) |
126 { | 130 { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 258 } |
255 ASSERT(!extensionObject.IsEmpty()); | 259 ASSERT(!extensionObject.IsEmpty()); |
256 V8HiddenPropertyName::setNamedHiddenReference(contextObject, referenceName,
extensionObject); | 260 V8HiddenPropertyName::setNamedHiddenReference(contextObject, referenceName,
extensionObject); |
257 return extensionObject; | 261 return extensionObject; |
258 } | 262 } |
259 | 263 |
260 enum ObjectType { | 264 enum ObjectType { |
261 kBuffer, kRenderbuffer, kTexture, kVertexAttrib | 265 kBuffer, kRenderbuffer, kTexture, kVertexAttrib |
262 }; | 266 }; |
263 | 267 |
264 static void getObjectParameter(const v8::FunctionCallbackInfo<v8::Value>& info,
ObjectType objectType, const char* method) | 268 static void getObjectParameter(const v8::FunctionCallbackInfo<v8::Value>& info,
ObjectType objectType, ExceptionState& exceptionState) |
265 { | 269 { |
266 if (info.Length() != 2) { | 270 if (info.Length() != 2) { |
267 throwTypeError(ExceptionMessages::failedToExecute(method, "WebGLRenderin
gContext", ExceptionMessages::notEnoughArguments(2, info.Length())), info.GetIso
late()); | 271 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 272 exceptionState.throwIfNeeded(); |
268 return; | 273 return; |
269 } | 274 } |
270 | 275 |
271 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 276 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
272 unsigned target = toInt32(info[0]); | 277 unsigned target = toInt32(info[0], exceptionState); |
273 unsigned pname = toInt32(info[1]); | 278 if (exceptionState.throwIfNeeded()) |
| 279 return; |
| 280 unsigned pname = toInt32(info[1], exceptionState); |
| 281 if (exceptionState.throwIfNeeded()) |
| 282 return; |
274 WebGLGetInfo args; | 283 WebGLGetInfo args; |
275 switch (objectType) { | 284 switch (objectType) { |
276 case kBuffer: | 285 case kBuffer: |
277 args = context->getBufferParameter(target, pname); | 286 args = context->getBufferParameter(target, pname); |
278 break; | 287 break; |
279 case kRenderbuffer: | 288 case kRenderbuffer: |
280 args = context->getRenderbufferParameter(target, pname); | 289 args = context->getRenderbufferParameter(target, pname); |
281 break; | 290 break; |
282 case kTexture: | 291 case kTexture: |
283 args = context->getTexParameter(target, pname); | 292 args = context->getTexParameter(target, pname); |
284 break; | 293 break; |
285 case kVertexAttrib: | 294 case kVertexAttrib: |
286 // target => index | 295 // target => index |
287 args = context->getVertexAttrib(target, pname); | 296 args = context->getVertexAttrib(target, pname); |
288 break; | 297 break; |
289 default: | 298 default: |
290 notImplemented(); | 299 notImplemented(); |
291 break; | 300 break; |
292 } | 301 } |
293 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); | 302 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); |
294 } | 303 } |
295 | 304 |
296 static WebGLUniformLocation* toWebGLUniformLocation(v8::Handle<v8::Value> value,
bool& ok, v8::Isolate* isolate) | 305 static WebGLUniformLocation* toWebGLUniformLocation(v8::Handle<v8::Value> value,
v8::Isolate* isolate) |
297 { | 306 { |
298 ok = false; | 307 if (!V8WebGLUniformLocation::hasInstance(value, isolate, worldType(isolate))
) |
299 WebGLUniformLocation* location = 0; | 308 return 0; |
300 if (V8WebGLUniformLocation::hasInstance(value, isolate, worldType(isolate)))
{ | 309 return V8WebGLUniformLocation::toNative(value->ToObject()); |
301 location = V8WebGLUniformLocation::toNative(value->ToObject()); | |
302 ok = true; | |
303 } | |
304 return location; | |
305 } | 310 } |
306 | 311 |
307 enum WhichProgramCall { | 312 enum WhichProgramCall { |
308 kProgramParameter, kUniform | 313 kProgramParameter, kUniform |
309 }; | 314 }; |
310 | 315 |
311 void V8WebGLRenderingContext::getAttachedShadersMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) | 316 void V8WebGLRenderingContext::getAttachedShadersMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) |
312 { | 317 { |
| 318 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getAttached
Shaders", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
313 if (info.Length() < 1) { | 319 if (info.Length() < 1) { |
314 throwTypeError(ExceptionMessages::failedToExecute("getAttachedShaders",
"WebGLRenderingContext", ExceptionMessages::notEnoughArguments(1, info.Length())
), info.GetIsolate()); | 320 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i
nfo.Length())); |
| 321 exceptionState.throwIfNeeded(); |
315 return; | 322 return; |
316 } | 323 } |
317 | 324 |
| 325 const int programArgumentIndex = 0; |
318 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 326 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
319 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram::has
Instance(info[0], info.GetIsolate(), worldType(info.GetIsolate()))) { | 327 if (info.Length() > 0 && !isUndefinedOrNull(info[programArgumentIndex]) && !
V8WebGLProgram::hasInstance(info[programArgumentIndex], info.GetIsolate(), world
Type(info.GetIsolate()))) { |
320 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 328 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(p
rogramArgumentIndex + 1, "is not a WebGLProgram object.")); |
| 329 exceptionState.throwIfNeeded(); |
321 return; | 330 return; |
322 } | 331 } |
323 WebGLProgram* program = V8WebGLProgram::hasInstance(info[0], info.GetIsolate
(), worldType(info.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Obje
ct>::Cast(info[0])) : 0; | 332 WebGLProgram* program = V8WebGLProgram::hasInstance(info[0], info.GetIsolate
(), worldType(info.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Obje
ct>::Cast(info[0])) : 0; |
324 Vector<RefPtr<WebGLShader> > shaders; | 333 Vector<RefPtr<WebGLShader> > shaders; |
325 bool succeed = context->getAttachedShaders(program, shaders); | 334 bool succeed = context->getAttachedShaders(program, shaders); |
326 if (!succeed) { | 335 if (!succeed) { |
327 v8SetReturnValueNull(info); | 336 v8SetReturnValueNull(info); |
328 return; | 337 return; |
329 } | 338 } |
330 v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), shaders.size(
)); | 339 v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), shaders.size(
)); |
331 for (size_t ii = 0; ii < shaders.size(); ++ii) | 340 for (size_t ii = 0; ii < shaders.size(); ++ii) |
332 array->Set(v8::Integer::New(info.GetIsolate(), ii), toV8(shaders[ii].get
(), info.Holder(), info.GetIsolate())); | 341 array->Set(v8::Integer::New(info.GetIsolate(), ii), toV8(shaders[ii].get
(), info.Holder(), info.GetIsolate())); |
333 v8SetReturnValue(info, array); | 342 v8SetReturnValue(info, array); |
334 } | 343 } |
335 | 344 |
336 void V8WebGLRenderingContext::getBufferParameterMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) | 345 void V8WebGLRenderingContext::getBufferParameterMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) |
337 { | 346 { |
338 getObjectParameter(info, kBuffer, "getBufferParameter"); | 347 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getBufferPa
rameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 348 getObjectParameter(info, kBuffer, exceptionState); |
339 } | 349 } |
340 | 350 |
341 void V8WebGLRenderingContext::getExtensionMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 351 void V8WebGLRenderingContext::getExtensionMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) |
342 { | 352 { |
| 353 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getExtensio
n", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
343 WebGLRenderingContext* imp = V8WebGLRenderingContext::toNative(info.Holder()
); | 354 WebGLRenderingContext* imp = V8WebGLRenderingContext::toNative(info.Holder()
); |
344 if (info.Length() < 1) { | 355 if (info.Length() < 1) { |
345 throwTypeError(ExceptionMessages::failedToExecute("getExtension", "WebGL
RenderingContext", ExceptionMessages::notEnoughArguments(1, info.Length())), inf
o.GetIsolate()); | 356 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i
nfo.Length())); |
| 357 exceptionState.throwIfNeeded(); |
346 return; | 358 return; |
347 } | 359 } |
348 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, info[0]); | 360 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, info[0]); |
349 RefPtr<WebGLExtension> extension(imp->getExtension(name)); | 361 RefPtr<WebGLExtension> extension(imp->getExtension(name)); |
350 v8SetReturnValue(info, toV8Object(extension.get(), info.Holder(), info.GetIs
olate())); | 362 v8SetReturnValue(info, toV8Object(extension.get(), info.Holder(), info.GetIs
olate())); |
351 } | 363 } |
352 | 364 |
353 void V8WebGLRenderingContext::getFramebufferAttachmentParameterMethodCustom(cons
t v8::FunctionCallbackInfo<v8::Value>& info) | 365 void V8WebGLRenderingContext::getFramebufferAttachmentParameterMethodCustom(cons
t v8::FunctionCallbackInfo<v8::Value>& info) |
354 { | 366 { |
| 367 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getFramebuf
ferAttachmentParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate
()); |
355 if (info.Length() != 3) { | 368 if (info.Length() != 3) { |
356 throwTypeError(ExceptionMessages::failedToExecute("getFramebufferAttachm
entParameter", "WebGLRenderingContext", ExceptionMessages::notEnoughArguments(3,
info.Length())), info.GetIsolate()); | 369 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, i
nfo.Length())); |
| 370 exceptionState.throwIfNeeded(); |
357 return; | 371 return; |
358 } | 372 } |
359 | 373 |
360 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 374 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
361 unsigned target = toInt32(info[0]); | 375 unsigned target = toInt32(info[0]); |
362 unsigned attachment = toInt32(info[1]); | 376 unsigned attachment = toInt32(info[1], exceptionState); |
363 unsigned pname = toInt32(info[2]); | 377 if (exceptionState.throwIfNeeded()) |
| 378 return; |
| 379 unsigned pname = toInt32(info[2], exceptionState); |
| 380 if (exceptionState.throwIfNeeded()) |
| 381 return; |
364 WebGLGetInfo args = context->getFramebufferAttachmentParameter(target, attac
hment, pname); | 382 WebGLGetInfo args = context->getFramebufferAttachmentParameter(target, attac
hment, pname); |
365 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); | 383 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); |
366 } | 384 } |
367 | 385 |
368 void V8WebGLRenderingContext::getParameterMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 386 void V8WebGLRenderingContext::getParameterMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) |
369 { | 387 { |
| 388 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getParamete
r", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
370 if (info.Length() != 1) { | 389 if (info.Length() != 1) { |
371 throwTypeError(ExceptionMessages::failedToExecute("getParameter", "WebGL
RenderingContext", ExceptionMessages::notEnoughArguments(1, info.Length())), inf
o.GetIsolate()); | 390 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i
nfo.Length())); |
| 391 exceptionState.throwIfNeeded(); |
372 return; | 392 return; |
373 } | 393 } |
374 | 394 |
375 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 395 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
376 unsigned pname = toInt32(info[0]); | 396 unsigned pname = toInt32(info[0], exceptionState); |
| 397 if (exceptionState.throwIfNeeded()) |
| 398 return; |
377 WebGLGetInfo args = context->getParameter(pname); | 399 WebGLGetInfo args = context->getParameter(pname); |
378 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); | 400 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); |
379 } | 401 } |
380 | 402 |
381 void V8WebGLRenderingContext::getProgramParameterMethodCustom(const v8::Function
CallbackInfo<v8::Value>& info) | 403 void V8WebGLRenderingContext::getProgramParameterMethodCustom(const v8::Function
CallbackInfo<v8::Value>& info) |
382 { | 404 { |
| 405 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getProgramP
arameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
383 if (info.Length() != 2) { | 406 if (info.Length() != 2) { |
384 throwTypeError(ExceptionMessages::failedToExecute("getProgramParameter",
"WebGLRenderingContext", ExceptionMessages::notEnoughArguments(2, info.Length()
)), info.GetIsolate()); | 407 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 408 exceptionState.throwIfNeeded(); |
385 return; | 409 return; |
386 } | 410 } |
387 | 411 |
| 412 const int programArgumentIndex = 0; |
388 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 413 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
389 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram::has
Instance(info[0], info.GetIsolate(), worldType(info.GetIsolate()))) { | 414 if (info.Length() > 0 && !isUndefinedOrNull(info[programArgumentIndex]) && !
V8WebGLProgram::hasInstance(info[programArgumentIndex], info.GetIsolate(), world
Type(info.GetIsolate()))) { |
390 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 415 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(p
rogramArgumentIndex + 1, "is not a WebGLProgram object.")); |
| 416 exceptionState.throwIfNeeded(); |
391 return; | 417 return; |
392 } | 418 } |
393 WebGLProgram* program = V8WebGLProgram::hasInstance(info[0], info.GetIsolate
(), worldType(info.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Obje
ct>::Cast(info[0])) : 0; | 419 WebGLProgram* program = V8WebGLProgram::hasInstance(info[0], info.GetIsolate
(), worldType(info.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Obje
ct>::Cast(info[0])) : 0; |
394 unsigned pname = toInt32(info[1]); | 420 unsigned pname = toInt32(info[1], exceptionState); |
| 421 if (exceptionState.throwIfNeeded()) |
| 422 return; |
395 WebGLGetInfo args = context->getProgramParameter(program, pname); | 423 WebGLGetInfo args = context->getProgramParameter(program, pname); |
396 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); | 424 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); |
397 } | 425 } |
398 | 426 |
399 void V8WebGLRenderingContext::getRenderbufferParameterMethodCustom(const v8::Fun
ctionCallbackInfo<v8::Value>& info) | 427 void V8WebGLRenderingContext::getRenderbufferParameterMethodCustom(const v8::Fun
ctionCallbackInfo<v8::Value>& info) |
400 { | 428 { |
401 getObjectParameter(info, kRenderbuffer, "getRenderbufferParameter"); | 429 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getRenderbu
fferParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 430 getObjectParameter(info, kRenderbuffer, exceptionState); |
402 } | 431 } |
403 | 432 |
404 void V8WebGLRenderingContext::getShaderParameterMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) | 433 void V8WebGLRenderingContext::getShaderParameterMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) |
405 { | 434 { |
| 435 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getShaderPa
rameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
406 if (info.Length() != 2) { | 436 if (info.Length() != 2) { |
407 throwTypeError(ExceptionMessages::failedToExecute("getShaderParameter",
"WebGLRenderingContext", ExceptionMessages::notEnoughArguments(2, info.Length())
), info.GetIsolate()); | 437 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 438 exceptionState.throwIfNeeded(); |
408 return; | 439 return; |
409 } | 440 } |
410 | 441 |
| 442 const int shaderArgumentIndex = 0; |
411 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 443 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
412 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLShader::hasI
nstance(info[0], info.GetIsolate(), worldType(info.GetIsolate()))) { | 444 if (info.Length() > 0 && !isUndefinedOrNull(info[shaderArgumentIndex]) && !V
8WebGLShader::hasInstance(info[shaderArgumentIndex], info.GetIsolate(), worldTyp
e(info.GetIsolate()))) { |
413 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 445 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(s
haderArgumentIndex + 1, "is not a WebGLShader object.")); |
| 446 exceptionState.throwIfNeeded(); |
414 return; | 447 return; |
415 } | 448 } |
416 WebGLShader* shader = V8WebGLShader::hasInstance(info[0], info.GetIsolate(),
worldType(info.GetIsolate())) ? V8WebGLShader::toNative(v8::Handle<v8::Object>:
:Cast(info[0])) : 0; | 449 WebGLShader* shader = V8WebGLShader::hasInstance(info[shaderArgumentIndex],
info.GetIsolate(), worldType(info.GetIsolate())) ? V8WebGLShader::toNative(v8::H
andle<v8::Object>::Cast(info[0])) : 0; |
417 unsigned pname = toInt32(info[1]); | 450 unsigned pname = toInt32(info[1], exceptionState); |
| 451 if (exceptionState.throwIfNeeded()) |
| 452 return; |
418 WebGLGetInfo args = context->getShaderParameter(shader, pname); | 453 WebGLGetInfo args = context->getShaderParameter(shader, pname); |
419 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); | 454 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); |
420 } | 455 } |
421 | 456 |
422 void V8WebGLRenderingContext::getSupportedExtensionsMethodCustom(const v8::Funct
ionCallbackInfo<v8::Value>& info) | 457 void V8WebGLRenderingContext::getSupportedExtensionsMethodCustom(const v8::Funct
ionCallbackInfo<v8::Value>& info) |
423 { | 458 { |
424 WebGLRenderingContext* imp = V8WebGLRenderingContext::toNative(info.Holder()
); | 459 WebGLRenderingContext* imp = V8WebGLRenderingContext::toNative(info.Holder()
); |
425 if (imp->isContextLost()) { | 460 if (imp->isContextLost()) { |
426 v8SetReturnValueNull(info); | 461 v8SetReturnValueNull(info); |
427 return; | 462 return; |
428 } | 463 } |
429 | 464 |
430 Vector<String> value = imp->getSupportedExtensions(); | 465 Vector<String> value = imp->getSupportedExtensions(); |
431 v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), value.size())
; | 466 v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), value.size())
; |
432 for (size_t ii = 0; ii < value.size(); ++ii) | 467 for (size_t ii = 0; ii < value.size(); ++ii) |
433 array->Set(v8::Integer::New(info.GetIsolate(), ii), v8String(info.GetIso
late(), value[ii])); | 468 array->Set(v8::Integer::New(info.GetIsolate(), ii), v8String(info.GetIso
late(), value[ii])); |
434 v8SetReturnValue(info, array); | 469 v8SetReturnValue(info, array); |
435 } | 470 } |
436 | 471 |
437 void V8WebGLRenderingContext::getTexParameterMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 472 void V8WebGLRenderingContext::getTexParameterMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) |
438 { | 473 { |
439 getObjectParameter(info, kTexture, "getTexParameter"); | 474 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getTexParam
eter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 475 getObjectParameter(info, kTexture, exceptionState); |
440 } | 476 } |
441 | 477 |
442 void V8WebGLRenderingContext::getUniformMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 478 void V8WebGLRenderingContext::getUniformMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
443 { | 479 { |
| 480 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getUniform"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
444 if (info.Length() != 2) { | 481 if (info.Length() != 2) { |
445 throwTypeError(ExceptionMessages::failedToExecute("getUniform", "WebGLRe
nderingContext", ExceptionMessages::notEnoughArguments(2, info.Length())), info.
GetIsolate()); | 482 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 483 exceptionState.throwIfNeeded(); |
446 return; | 484 return; |
447 } | 485 } |
448 | 486 |
| 487 const int programArgumentIndex = 0; |
449 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 488 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
450 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram::has
Instance(info[0], info.GetIsolate(), worldType(info.GetIsolate()))) { | 489 if (info.Length() > 0 && !isUndefinedOrNull(info[programArgumentIndex]) && !
V8WebGLProgram::hasInstance(info[programArgumentIndex], info.GetIsolate(), world
Type(info.GetIsolate()))) { |
451 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 490 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(p
rogramArgumentIndex + 1, "is not a WebGLProgram object.")); |
| 491 exceptionState.throwIfNeeded(); |
452 return; | 492 return; |
453 } | 493 } |
454 WebGLProgram* program = V8WebGLProgram::hasInstance(info[0], info.GetIsolate
(), worldType(info.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Obje
ct>::Cast(info[0])) : 0; | 494 WebGLProgram* program = V8WebGLProgram::hasInstance(info[programArgumentInde
x], info.GetIsolate(), worldType(info.GetIsolate())) ? V8WebGLProgram::toNative(
v8::Handle<v8::Object>::Cast(info[0])) : 0; |
455 | 495 |
456 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !V8WebGLUniformLocat
ion::hasInstance(info[1], info.GetIsolate(), worldType(info.GetIsolate()))) { | 496 const int uniformArgumentIndex = 1; |
457 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 497 if (info.Length() > 1 && !isUndefinedOrNull(info[uniformArgumentIndex]) && !
V8WebGLUniformLocation::hasInstance(info[uniformArgumentIndex], info.GetIsolate(
), worldType(info.GetIsolate()))) { |
| 498 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(u
niformArgumentIndex + 1, "is not a WebGLUniformLocation object.")); |
| 499 exceptionState.throwIfNeeded(); |
458 return; | 500 return; |
459 } | 501 } |
460 bool ok = false; | 502 const int uniformLocationArgumentIndex = 1; |
461 WebGLUniformLocation* location = toWebGLUniformLocation(info[1], ok, info.Ge
tIsolate()); | 503 WebGLUniformLocation* location = toWebGLUniformLocation(info[uniformLocation
ArgumentIndex], info.GetIsolate()); |
462 | 504 |
463 WebGLGetInfo args = context->getUniform(program, location); | 505 WebGLGetInfo args = context->getUniform(program, location); |
464 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); | 506 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); |
465 } | 507 } |
466 | 508 |
467 void V8WebGLRenderingContext::getVertexAttribMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 509 void V8WebGLRenderingContext::getVertexAttribMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) |
468 { | 510 { |
469 getObjectParameter(info, kVertexAttrib, "getVertexAttrib"); | 511 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getVertexAt
trib", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 512 getObjectParameter(info, kVertexAttrib, exceptionState); |
470 } | 513 } |
471 | 514 |
472 enum FunctionToCall { | 515 enum FunctionToCall { |
473 kUniform1v, kUniform2v, kUniform3v, kUniform4v, | 516 kUniform1v, kUniform2v, kUniform3v, kUniform4v, |
474 kVertexAttrib1v, kVertexAttrib2v, kVertexAttrib3v, kVertexAttrib4v | 517 kVertexAttrib1v, kVertexAttrib2v, kVertexAttrib3v, kVertexAttrib4v |
475 }; | 518 }; |
476 | 519 |
477 bool isFunctionToCallForAttribute(FunctionToCall functionToCall) | 520 bool isFunctionToCallForAttribute(FunctionToCall functionToCall) |
478 { | 521 { |
479 switch (functionToCall) { | 522 switch (functionToCall) { |
480 case kVertexAttrib1v: | 523 case kVertexAttrib1v: |
481 case kVertexAttrib2v: | 524 case kVertexAttrib2v: |
482 case kVertexAttrib3v: | 525 case kVertexAttrib3v: |
483 case kVertexAttrib4v: | 526 case kVertexAttrib4v: |
484 return true; | 527 return true; |
485 default: | 528 default: |
486 break; | 529 break; |
487 } | 530 } |
488 return false; | 531 return false; |
489 } | 532 } |
490 | 533 |
491 static void vertexAttribAndUniformHelperf(const v8::FunctionCallbackInfo<v8::Val
ue>& info, FunctionToCall functionToCall, const char* method) | 534 static void vertexAttribAndUniformHelperf(const v8::FunctionCallbackInfo<v8::Val
ue>& info, FunctionToCall functionToCall, ExceptionState& exceptionState) |
492 { | 535 { |
493 // Forms: | 536 // Forms: |
494 // * glUniform1fv(WebGLUniformLocation location, Array data); | 537 // * glUniform1fv(WebGLUniformLocation location, Array data); |
495 // * glUniform1fv(WebGLUniformLocation location, Float32Array data); | 538 // * glUniform1fv(WebGLUniformLocation location, Float32Array data); |
496 // * glUniform2fv(WebGLUniformLocation location, Array data); | 539 // * glUniform2fv(WebGLUniformLocation location, Array data); |
497 // * glUniform2fv(WebGLUniformLocation location, Float32Array data); | 540 // * glUniform2fv(WebGLUniformLocation location, Float32Array data); |
498 // * glUniform3fv(WebGLUniformLocation location, Array data); | 541 // * glUniform3fv(WebGLUniformLocation location, Array data); |
499 // * glUniform3fv(WebGLUniformLocation location, Float32Array data); | 542 // * glUniform3fv(WebGLUniformLocation location, Float32Array data); |
500 // * glUniform4fv(WebGLUniformLocation location, Array data); | 543 // * glUniform4fv(WebGLUniformLocation location, Array data); |
501 // * glUniform4fv(WebGLUniformLocation location, Float32Array data); | 544 // * glUniform4fv(WebGLUniformLocation location, Float32Array data); |
502 // * glVertexAttrib1fv(GLint index, Array data); | 545 // * glVertexAttrib1fv(GLint index, Array data); |
503 // * glVertexAttrib1fv(GLint index, Float32Array data); | 546 // * glVertexAttrib1fv(GLint index, Float32Array data); |
504 // * glVertexAttrib2fv(GLint index, Array data); | 547 // * glVertexAttrib2fv(GLint index, Array data); |
505 // * glVertexAttrib2fv(GLint index, Float32Array data); | 548 // * glVertexAttrib2fv(GLint index, Float32Array data); |
506 // * glVertexAttrib3fv(GLint index, Array data); | 549 // * glVertexAttrib3fv(GLint index, Array data); |
507 // * glVertexAttrib3fv(GLint index, Float32Array data); | 550 // * glVertexAttrib3fv(GLint index, Float32Array data); |
508 // * glVertexAttrib4fv(GLint index, Array data); | 551 // * glVertexAttrib4fv(GLint index, Array data); |
509 // * glVertexAttrib4fv(GLint index, Float32Array data); | 552 // * glVertexAttrib4fv(GLint index, Float32Array data); |
510 | 553 |
511 if (info.Length() != 2) { | 554 if (info.Length() != 2) { |
512 throwTypeError(ExceptionMessages::failedToExecute(method, "WebGLRenderin
gContext", ExceptionMessages::notEnoughArguments(2, info.Length())), info.GetIso
late()); | 555 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 556 exceptionState.throwIfNeeded(); |
513 return; | 557 return; |
514 } | 558 } |
515 | 559 |
516 bool ok = false; | |
517 int index = -1; | 560 int index = -1; |
518 WebGLUniformLocation* location = 0; | 561 WebGLUniformLocation* location = 0; |
519 | 562 |
520 if (isFunctionToCallForAttribute(functionToCall)) | 563 if (isFunctionToCallForAttribute(functionToCall)) { |
521 index = toInt32(info[0]); | 564 index = toInt32(info[0], exceptionState); |
522 else { | 565 if (exceptionState.throwIfNeeded()) |
523 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLUniformL
ocation::hasInstance(info[0], info.GetIsolate(), worldType(info.GetIsolate())))
{ | 566 return; |
524 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 567 } else { |
| 568 const int uniformLocationArgumentIndex = 0; |
| 569 if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgument
Index]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentInde
x], info.GetIsolate(), worldType(info.GetIsolate()))) { |
| 570 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentTy
pe(uniformLocationArgumentIndex + 1, "is not a WebGLUniformLocation object.")); |
| 571 exceptionState.throwIfNeeded(); |
525 return; | 572 return; |
526 } | 573 } |
527 location = toWebGLUniformLocation(info[0], ok, info.GetIsolate()); | 574 location = toWebGLUniformLocation(info[uniformLocationArgumentIndex], in
fo.GetIsolate()); |
528 } | 575 } |
529 | 576 |
530 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 577 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
531 | 578 |
532 if (V8Float32Array::hasInstance(info[1], info.GetIsolate(), worldType(info.G
etIsolate()))) { | 579 const int indexArrayArgument = 1; |
533 Float32Array* array = V8Float32Array::toNative(info[1]->ToObject()); | 580 if (V8Float32Array::hasInstance(info[indexArrayArgument], info.GetIsolate(),
worldType(info.GetIsolate()))) { |
| 581 Float32Array* array = V8Float32Array::toNative(info[indexArrayArgument]-
>ToObject()); |
534 ASSERT(array != NULL); | 582 ASSERT(array != NULL); |
535 switch (functionToCall) { | 583 switch (functionToCall) { |
536 case kUniform1v: context->uniform1fv(location, array); break; | 584 case kUniform1v: context->uniform1fv(location, array); break; |
537 case kUniform2v: context->uniform2fv(location, array); break; | 585 case kUniform2v: context->uniform2fv(location, array); break; |
538 case kUniform3v: context->uniform3fv(location, array); break; | 586 case kUniform3v: context->uniform3fv(location, array); break; |
539 case kUniform4v: context->uniform4fv(location, array); break; | 587 case kUniform4v: context->uniform4fv(location, array); break; |
540 case kVertexAttrib1v: context->vertexAttrib1fv(index, array); break; | 588 case kVertexAttrib1v: context->vertexAttrib1fv(index, array); break; |
541 case kVertexAttrib2v: context->vertexAttrib2fv(index, array); break; | 589 case kVertexAttrib2v: context->vertexAttrib2fv(index, array); break; |
542 case kVertexAttrib3v: context->vertexAttrib3fv(index, array); break; | 590 case kVertexAttrib3v: context->vertexAttrib3fv(index, array); break; |
543 case kVertexAttrib4v: context->vertexAttrib4fv(index, array); break; | 591 case kVertexAttrib4v: context->vertexAttrib4fv(index, array); break; |
544 default: ASSERT_NOT_REACHED(); break; | 592 default: ASSERT_NOT_REACHED(); break; |
545 } | 593 } |
546 return; | 594 return; |
547 } | 595 } |
548 | 596 |
549 if (info[1].IsEmpty() || !info[1]->IsArray()) { | 597 if (info[indexArrayArgument].IsEmpty() || !info[indexArrayArgument]->IsArray
()) { |
550 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 598 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(i
ndexArrayArgument + 1, "is not an Array.")); |
| 599 exceptionState.throwIfNeeded(); |
551 return; | 600 return; |
552 } | 601 } |
553 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]); | 602 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]); |
554 uint32_t len = array->Length(); | 603 uint32_t len = array->Length(); |
555 float* data = jsArrayToFloatArray(array, len); | 604 float* data = jsArrayToFloatArray(array, len, exceptionState); |
| 605 if (exceptionState.throwIfNeeded()) |
| 606 return; |
556 if (!data) { | 607 if (!data) { |
557 // FIXME: consider different / better exception type. | 608 // FIXME: consider different / better exception type. |
558 setDOMException(SyntaxError, info.GetIsolate()); | 609 exceptionState.throwDOMException(SyntaxError, "Failed to convert array a
rgument"); |
| 610 exceptionState.throwIfNeeded(); |
559 return; | 611 return; |
560 } | 612 } |
561 switch (functionToCall) { | 613 switch (functionToCall) { |
562 case kUniform1v: context->uniform1fv(location, data, len); break; | 614 case kUniform1v: context->uniform1fv(location, data, len); break; |
563 case kUniform2v: context->uniform2fv(location, data, len); break; | 615 case kUniform2v: context->uniform2fv(location, data, len); break; |
564 case kUniform3v: context->uniform3fv(location, data, len); break; | 616 case kUniform3v: context->uniform3fv(location, data, len); break; |
565 case kUniform4v: context->uniform4fv(location, data, len); break; | 617 case kUniform4v: context->uniform4fv(location, data, len); break; |
566 case kVertexAttrib1v: context->vertexAttrib1fv(index, data, len); break; | 618 case kVertexAttrib1v: context->vertexAttrib1fv(index, data, len); break; |
567 case kVertexAttrib2v: context->vertexAttrib2fv(index, data, len); break; | 619 case kVertexAttrib2v: context->vertexAttrib2fv(index, data, len); break; |
568 case kVertexAttrib3v: context->vertexAttrib3fv(index, data, len); break; | 620 case kVertexAttrib3v: context->vertexAttrib3fv(index, data, len); break; |
569 case kVertexAttrib4v: context->vertexAttrib4fv(index, data, len); break; | 621 case kVertexAttrib4v: context->vertexAttrib4fv(index, data, len); break; |
570 default: ASSERT_NOT_REACHED(); break; | 622 default: ASSERT_NOT_REACHED(); break; |
571 } | 623 } |
572 fastFree(data); | 624 fastFree(data); |
573 } | 625 } |
574 | 626 |
575 static void uniformHelperi(const v8::FunctionCallbackInfo<v8::Value>& info, Func
tionToCall functionToCall, const char* method) | 627 static void uniformHelperi(const v8::FunctionCallbackInfo<v8::Value>& info, Func
tionToCall functionToCall, ExceptionState& exceptionState) |
576 { | 628 { |
577 // Forms: | 629 // Forms: |
578 // * glUniform1iv(GLUniformLocation location, Array data); | 630 // * glUniform1iv(GLUniformLocation location, Array data); |
579 // * glUniform1iv(GLUniformLocation location, Int32Array data); | 631 // * glUniform1iv(GLUniformLocation location, Int32Array data); |
580 // * glUniform2iv(GLUniformLocation location, Array data); | 632 // * glUniform2iv(GLUniformLocation location, Array data); |
581 // * glUniform2iv(GLUniformLocation location, Int32Array data); | 633 // * glUniform2iv(GLUniformLocation location, Int32Array data); |
582 // * glUniform3iv(GLUniformLocation location, Array data); | 634 // * glUniform3iv(GLUniformLocation location, Array data); |
583 // * glUniform3iv(GLUniformLocation location, Int32Array data); | 635 // * glUniform3iv(GLUniformLocation location, Int32Array data); |
584 // * glUniform4iv(GLUniformLocation location, Array data); | 636 // * glUniform4iv(GLUniformLocation location, Array data); |
585 // * glUniform4iv(GLUniformLocation location, Int32Array data); | 637 // * glUniform4iv(GLUniformLocation location, Int32Array data); |
586 | 638 |
587 if (info.Length() != 2) { | 639 if (info.Length() != 2) { |
588 throwTypeError(ExceptionMessages::failedToExecute(method, "WebGLRenderin
gContext", ExceptionMessages::notEnoughArguments(2, info.Length())), info.GetIso
late()); | 640 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 641 exceptionState.throwIfNeeded(); |
589 return; | 642 return; |
590 } | 643 } |
591 | 644 |
| 645 const int uniformLocationArgumentIndex = 0; |
592 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 646 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
593 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLUniformLocat
ion::hasInstance(info[0], info.GetIsolate(), worldType(info.GetIsolate()))) { | 647 if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgumentInde
x]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentIndex],
info.GetIsolate(), worldType(info.GetIsolate()))) { |
594 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 648 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(u
niformLocationArgumentIndex + 1, "is not a WebGLUniformLocation object.")); |
| 649 exceptionState.throwIfNeeded(); |
595 return; | 650 return; |
596 } | 651 } |
597 bool ok = false; | 652 WebGLUniformLocation* location = toWebGLUniformLocation(info[uniformLocation
ArgumentIndex], info.GetIsolate()); |
598 WebGLUniformLocation* location = toWebGLUniformLocation(info[0], ok, info.Ge
tIsolate()); | |
599 | 653 |
600 if (V8Int32Array::hasInstance(info[1], info.GetIsolate(), worldType(info.Get
Isolate()))) { | 654 const int indexArrayArgumentIndex = 1; |
601 Int32Array* array = V8Int32Array::toNative(info[1]->ToObject()); | 655 if (V8Int32Array::hasInstance(info[indexArrayArgumentIndex], info.GetIsolate
(), worldType(info.GetIsolate()))) { |
| 656 Int32Array* array = V8Int32Array::toNative(info[indexArrayArgumentIndex]
->ToObject()); |
602 ASSERT(array != NULL); | 657 ASSERT(array != NULL); |
603 switch (functionToCall) { | 658 switch (functionToCall) { |
604 case kUniform1v: context->uniform1iv(location, array); break; | 659 case kUniform1v: context->uniform1iv(location, array); break; |
605 case kUniform2v: context->uniform2iv(location, array); break; | 660 case kUniform2v: context->uniform2iv(location, array); break; |
606 case kUniform3v: context->uniform3iv(location, array); break; | 661 case kUniform3v: context->uniform3iv(location, array); break; |
607 case kUniform4v: context->uniform4iv(location, array); break; | 662 case kUniform4v: context->uniform4iv(location, array); break; |
608 default: ASSERT_NOT_REACHED(); break; | 663 default: ASSERT_NOT_REACHED(); break; |
609 } | 664 } |
610 return; | 665 return; |
611 } | 666 } |
612 | 667 |
613 if (info[1].IsEmpty() || !info[1]->IsArray()) { | 668 if (info[indexArrayArgumentIndex].IsEmpty() || !info[indexArrayArgumentIndex
]->IsArray()) { |
614 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 669 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(i
ndexArrayArgumentIndex + 1, "is not an Array.")); |
| 670 exceptionState.throwIfNeeded(); |
615 return; | 671 return; |
616 } | 672 } |
617 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]); | 673 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[indexArrayArgu
mentIndex]); |
618 uint32_t len = array->Length(); | 674 uint32_t len = array->Length(); |
619 int* data = jsArrayToIntArray(array, len); | 675 int* data = jsArrayToIntArray(array, len, exceptionState); |
| 676 if (exceptionState.throwIfNeeded()) |
| 677 return; |
620 if (!data) { | 678 if (!data) { |
621 // FIXME: consider different / better exception type. | 679 // FIXME: consider different / better exception type. |
622 setDOMException(SyntaxError, info.GetIsolate()); | 680 exceptionState.throwDOMException(SyntaxError, "Failed to convert array a
rgument"); |
| 681 exceptionState.throwIfNeeded(); |
623 return; | 682 return; |
624 } | 683 } |
625 switch (functionToCall) { | 684 switch (functionToCall) { |
626 case kUniform1v: context->uniform1iv(location, data, len); break; | 685 case kUniform1v: context->uniform1iv(location, data, len); break; |
627 case kUniform2v: context->uniform2iv(location, data, len); break; | 686 case kUniform2v: context->uniform2iv(location, data, len); break; |
628 case kUniform3v: context->uniform3iv(location, data, len); break; | 687 case kUniform3v: context->uniform3iv(location, data, len); break; |
629 case kUniform4v: context->uniform4iv(location, data, len); break; | 688 case kUniform4v: context->uniform4iv(location, data, len); break; |
630 default: ASSERT_NOT_REACHED(); break; | 689 default: ASSERT_NOT_REACHED(); break; |
631 } | 690 } |
632 fastFree(data); | 691 fastFree(data); |
633 } | 692 } |
634 | 693 |
635 void V8WebGLRenderingContext::uniform1fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 694 void V8WebGLRenderingContext::uniform1fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
636 { | 695 { |
637 vertexAttribAndUniformHelperf(info, kUniform1v, "uniform1fv"); | 696 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform1fv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 697 vertexAttribAndUniformHelperf(info, kUniform1v, exceptionState); |
638 } | 698 } |
639 | 699 |
640 void V8WebGLRenderingContext::uniform1ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 700 void V8WebGLRenderingContext::uniform1ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
641 { | 701 { |
642 uniformHelperi(info, kUniform1v, "uniform1iv"); | 702 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform1iv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 703 uniformHelperi(info, kUniform1v, exceptionState); |
643 } | 704 } |
644 | 705 |
645 void V8WebGLRenderingContext::uniform2fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 706 void V8WebGLRenderingContext::uniform2fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
646 { | 707 { |
647 vertexAttribAndUniformHelperf(info, kUniform2v, "uniform2fv"); | 708 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform2fv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 709 vertexAttribAndUniformHelperf(info, kUniform2v, exceptionState); |
648 } | 710 } |
649 | 711 |
650 void V8WebGLRenderingContext::uniform2ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 712 void V8WebGLRenderingContext::uniform2ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
651 { | 713 { |
652 uniformHelperi(info, kUniform2v, "uniform2iv"); | 714 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform2iv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 715 uniformHelperi(info, kUniform2v, exceptionState); |
653 } | 716 } |
654 | 717 |
655 void V8WebGLRenderingContext::uniform3fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 718 void V8WebGLRenderingContext::uniform3fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
656 { | 719 { |
657 vertexAttribAndUniformHelperf(info, kUniform3v, "uniform3fv"); | 720 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform3fv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 721 vertexAttribAndUniformHelperf(info, kUniform3v, exceptionState); |
658 } | 722 } |
659 | 723 |
660 void V8WebGLRenderingContext::uniform3ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 724 void V8WebGLRenderingContext::uniform3ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
661 { | 725 { |
662 uniformHelperi(info, kUniform3v, "uniform3iv"); | 726 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform3iv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 727 uniformHelperi(info, kUniform3v, exceptionState); |
663 } | 728 } |
664 | 729 |
665 void V8WebGLRenderingContext::uniform4fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 730 void V8WebGLRenderingContext::uniform4fvMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
666 { | 731 { |
667 vertexAttribAndUniformHelperf(info, kUniform4v, "uniform4fv"); | 732 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform4fv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 733 vertexAttribAndUniformHelperf(info, kUniform4v, exceptionState); |
668 } | 734 } |
669 | 735 |
670 void V8WebGLRenderingContext::uniform4ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 736 void V8WebGLRenderingContext::uniform4ivMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
671 { | 737 { |
672 uniformHelperi(info, kUniform4v, "uniform4iv"); | 738 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform4iv"
, "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 739 uniformHelperi(info, kUniform4v, exceptionState); |
673 } | 740 } |
674 | 741 |
675 static void uniformMatrixHelper(const v8::FunctionCallbackInfo<v8::Value>& info,
int matrixSize, const char* method) | 742 static void uniformMatrixHelper(const v8::FunctionCallbackInfo<v8::Value>& info,
int matrixSize, ExceptionState& exceptionState) |
676 { | 743 { |
677 // Forms: | 744 // Forms: |
678 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Array data); | 745 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Array data); |
679 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Float32Array da
ta); | 746 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Float32Array da
ta); |
680 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Array data); | 747 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Array data); |
681 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Float32Array da
ta); | 748 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Float32Array da
ta); |
682 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Array data); | 749 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Array data); |
683 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Float32Array da
ta); | 750 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Float32Array da
ta); |
684 // | 751 // |
685 // FIXME: need to change to accept Float32Array as well. | 752 // FIXME: need to change to accept Float32Array as well. |
686 if (info.Length() != 3) { | 753 if (info.Length() != 3) { |
687 throwTypeError(ExceptionMessages::failedToExecute(method, "WebGLRenderin
gContext", ExceptionMessages::notEnoughArguments(3, info.Length())), info.GetIso
late()); | 754 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, i
nfo.Length())); |
| 755 exceptionState.throwIfNeeded(); |
688 return; | 756 return; |
689 } | 757 } |
690 | 758 |
691 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); | 759 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold
er()); |
692 | 760 |
693 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLUniformLocat
ion::hasInstance(info[0], info.GetIsolate(), worldType(info.GetIsolate()))) { | 761 const int uniformLocationArgumentIndex = 0; |
694 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 762 if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgumentInde
x]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentIndex],
info.GetIsolate(), worldType(info.GetIsolate()))) { |
| 763 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(u
niformLocationArgumentIndex + 1, "is not a WebGLUniformLocation object.")); |
| 764 exceptionState.throwIfNeeded(); |
695 return; | 765 return; |
696 } | 766 } |
697 bool ok = false; | 767 WebGLUniformLocation* location = toWebGLUniformLocation(info[uniformLocation
ArgumentIndex], info.GetIsolate()); |
698 WebGLUniformLocation* location = toWebGLUniformLocation(info[0], ok, info.Ge
tIsolate()); | |
699 | 768 |
700 bool transpose = info[1]->BooleanValue(); | 769 bool transpose = info[1]->BooleanValue(); |
701 if (V8Float32Array::hasInstance(info[2], info.GetIsolate(), worldType(info.G
etIsolate()))) { | 770 const int arrayArgumentIndex = 2; |
702 Float32Array* array = V8Float32Array::toNative(info[2]->ToObject()); | 771 if (V8Float32Array::hasInstance(info[arrayArgumentIndex], info.GetIsolate(),
worldType(info.GetIsolate()))) { |
| 772 Float32Array* array = V8Float32Array::toNative(info[arrayArgumentIndex]-
>ToObject()); |
703 ASSERT(array != NULL); | 773 ASSERT(array != NULL); |
704 switch (matrixSize) { | 774 switch (matrixSize) { |
705 case 2: context->uniformMatrix2fv(location, transpose, array); break; | 775 case 2: context->uniformMatrix2fv(location, transpose, array); break; |
706 case 3: context->uniformMatrix3fv(location, transpose, array); break; | 776 case 3: context->uniformMatrix3fv(location, transpose, array); break; |
707 case 4: context->uniformMatrix4fv(location, transpose, array); break; | 777 case 4: context->uniformMatrix4fv(location, transpose, array); break; |
708 default: ASSERT_NOT_REACHED(); break; | 778 default: ASSERT_NOT_REACHED(); break; |
709 } | 779 } |
710 return; | 780 return; |
711 } | 781 } |
712 | 782 |
713 if (info[2].IsEmpty() || !info[2]->IsArray()) { | 783 if (info[arrayArgumentIndex].IsEmpty() || !info[arrayArgumentIndex]->IsArray
()) { |
714 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 784 exceptionState.throwTypeError(ExceptionMessages::incorrectArgumentType(a
rrayArgumentIndex + 1, "is not an Array.")); |
| 785 exceptionState.throwIfNeeded(); |
715 return; | 786 return; |
716 } | 787 } |
717 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[2]); | 788 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[2]); |
718 uint32_t len = array->Length(); | 789 uint32_t len = array->Length(); |
719 float* data = jsArrayToFloatArray(array, len); | 790 float* data = jsArrayToFloatArray(array, len, exceptionState); |
| 791 if (exceptionState.throwIfNeeded()) |
| 792 return; |
720 if (!data) { | 793 if (!data) { |
721 // FIXME: consider different / better exception type. | 794 // FIXME: consider different / better exception type. |
722 setDOMException(SyntaxError, info.GetIsolate()); | 795 exceptionState.throwDOMException(SyntaxError, "failed to convert Array v
alue"); |
| 796 exceptionState.throwIfNeeded(); |
723 return; | 797 return; |
724 } | 798 } |
725 switch (matrixSize) { | 799 switch (matrixSize) { |
726 case 2: context->uniformMatrix2fv(location, transpose, data, len); break; | 800 case 2: context->uniformMatrix2fv(location, transpose, data, len); break; |
727 case 3: context->uniformMatrix3fv(location, transpose, data, len); break; | 801 case 3: context->uniformMatrix3fv(location, transpose, data, len); break; |
728 case 4: context->uniformMatrix4fv(location, transpose, data, len); break; | 802 case 4: context->uniformMatrix4fv(location, transpose, data, len); break; |
729 default: ASSERT_NOT_REACHED(); break; | 803 default: ASSERT_NOT_REACHED(); break; |
730 } | 804 } |
731 fastFree(data); | 805 fastFree(data); |
732 } | 806 } |
733 | 807 |
734 void V8WebGLRenderingContext::uniformMatrix2fvMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 808 void V8WebGLRenderingContext::uniformMatrix2fvMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) |
735 { | 809 { |
736 uniformMatrixHelper(info, 2, "uniformMatrix2fv"); | 810 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniformMatr
ix2fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 811 uniformMatrixHelper(info, 2, exceptionState); |
737 } | 812 } |
738 | 813 |
739 void V8WebGLRenderingContext::uniformMatrix3fvMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 814 void V8WebGLRenderingContext::uniformMatrix3fvMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) |
740 { | 815 { |
741 uniformMatrixHelper(info, 3, "uniformMatrix3fv"); | 816 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniformMatr
ix3fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 817 uniformMatrixHelper(info, 3, exceptionState); |
742 } | 818 } |
743 | 819 |
744 void V8WebGLRenderingContext::uniformMatrix4fvMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 820 void V8WebGLRenderingContext::uniformMatrix4fvMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) |
745 { | 821 { |
746 uniformMatrixHelper(info, 4, "uniformMatrix4fv"); | 822 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniformMatr
ix4fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 823 uniformMatrixHelper(info, 4, exceptionState); |
747 } | 824 } |
748 | 825 |
749 void V8WebGLRenderingContext::vertexAttrib1fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 826 void V8WebGLRenderingContext::vertexAttrib1fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) |
750 { | 827 { |
751 vertexAttribAndUniformHelperf(info, kVertexAttrib1v, "vertexAttrib1fv"); | 828 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri
b1fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 829 vertexAttribAndUniformHelperf(info, kVertexAttrib1v, exceptionState); |
752 } | 830 } |
753 | 831 |
754 void V8WebGLRenderingContext::vertexAttrib2fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 832 void V8WebGLRenderingContext::vertexAttrib2fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) |
755 { | 833 { |
756 vertexAttribAndUniformHelperf(info, kVertexAttrib2v, "vertexAttrib2fv"); | 834 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri
b2fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 835 vertexAttribAndUniformHelperf(info, kVertexAttrib2v, exceptionState); |
757 } | 836 } |
758 | 837 |
759 void V8WebGLRenderingContext::vertexAttrib3fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 838 void V8WebGLRenderingContext::vertexAttrib3fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) |
760 { | 839 { |
761 vertexAttribAndUniformHelperf(info, kVertexAttrib3v, "vertexAttrib3fv"); | 840 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri
b3fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 841 vertexAttribAndUniformHelperf(info, kVertexAttrib3v, exceptionState); |
762 } | 842 } |
763 | 843 |
764 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 844 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) |
765 { | 845 { |
766 vertexAttribAndUniformHelperf(info, kVertexAttrib4v, "vertexAttrib4fv"); | 846 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri
b4fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); |
| 847 vertexAttribAndUniformHelperf(info, kVertexAttrib4v, exceptionState); |
767 } | 848 } |
768 | 849 |
769 } // namespace WebCore | 850 } // namespace WebCore |
OLD | NEW |