Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: Source/bindings/core/v8/custom/V8WebGLRenderingContextCustom.cpp

Issue 389583002: Use code generator's argument processing in custom WebGL methods (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 static void getObjectParameter(const v8::FunctionCallbackInfo<v8::Value>& info, ObjectType objectType, ExceptionState& exceptionState) 286 static void getObjectParameter(const v8::FunctionCallbackInfo<v8::Value>& info, ObjectType objectType, ExceptionState& exceptionState)
287 { 287 {
288 if (info.Length() != 2) { 288 if (info.Length() != 2) {
289 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length())); 289 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
290 exceptionState.throwIfNeeded(); 290 exceptionState.throwIfNeeded();
291 return; 291 return;
292 } 292 }
293 293
294 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er()); 294 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
295 unsigned target = toInt32(info[0], exceptionState); 295 unsigned target;
Jens Widell 2014/07/11 12:24:30 These uses of toInt32() shared a common problem: i
296 if (exceptionState.throwIfNeeded()) 296 unsigned pname;
297 return; 297 {
298 unsigned pname = toInt32(info[1], exceptionState); 298 v8::TryCatch block;
299 if (exceptionState.throwIfNeeded()) 299 V8RethrowTryCatchScope rethrow(block);
300 return; 300 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(target, toUInt32(info[0], exceptio nState), exceptionState);
301 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exception State), exceptionState);
302 }
301 WebGLGetInfo args; 303 WebGLGetInfo args;
302 switch (objectType) { 304 switch (objectType) {
303 case kBuffer: 305 case kBuffer:
304 args = context->getBufferParameter(target, pname); 306 args = context->getBufferParameter(target, pname);
305 break; 307 break;
306 case kRenderbuffer: 308 case kRenderbuffer:
307 args = context->getRenderbufferParameter(target, pname); 309 args = context->getRenderbufferParameter(target, pname);
308 break; 310 break;
309 case kTexture: 311 case kTexture:
310 args = context->getTexParameter(target, pname); 312 args = context->getTexParameter(target, pname);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 void V8WebGLRenderingContext::getFramebufferAttachmentParameterMethodCustom(cons t v8::FunctionCallbackInfo<v8::Value>& info) 383 void V8WebGLRenderingContext::getFramebufferAttachmentParameterMethodCustom(cons t v8::FunctionCallbackInfo<v8::Value>& info)
382 { 384 {
383 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getFramebuf ferAttachmentParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate ()); 385 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getFramebuf ferAttachmentParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate ());
384 if (info.Length() != 3) { 386 if (info.Length() != 3) {
385 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, i nfo.Length())); 387 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, i nfo.Length()));
386 exceptionState.throwIfNeeded(); 388 exceptionState.throwIfNeeded();
387 return; 389 return;
388 } 390 }
389 391
390 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er()); 392 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
391 unsigned target = toInt32(info[0]); 393 unsigned target;
392 unsigned attachment = toInt32(info[1], exceptionState); 394 unsigned attachment;
393 if (exceptionState.throwIfNeeded()) 395 unsigned pname;
394 return; 396 {
395 unsigned pname = toInt32(info[2], exceptionState); 397 v8::TryCatch block;
396 if (exceptionState.throwIfNeeded()) 398 V8RethrowTryCatchScope rethrow(block);
397 return; 399 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(target, toUInt32(info[0], exceptio nState), exceptionState);
400 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(attachment, toUInt32(info[1], exce ptionState), exceptionState);
401 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[2], exception State), exceptionState);
402 }
398 WebGLGetInfo args = context->getFramebufferAttachmentParameter(target, attac hment, pname); 403 WebGLGetInfo args = context->getFramebufferAttachmentParameter(target, attac hment, pname);
399 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); 404 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
400 } 405 }
401 406
402 void V8WebGLRenderingContext::getParameterMethodCustom(const v8::FunctionCallbac kInfo<v8::Value>& info) 407 void V8WebGLRenderingContext::getParameterMethodCustom(const v8::FunctionCallbac kInfo<v8::Value>& info)
403 { 408 {
404 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getParamete r", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 409 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getParamete r", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
405 if (info.Length() != 1) { 410 if (info.Length() != 1) {
406 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i nfo.Length())); 411 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i nfo.Length()));
407 exceptionState.throwIfNeeded(); 412 exceptionState.throwIfNeeded();
408 return; 413 return;
409 } 414 }
410 415
411 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er()); 416 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
412 unsigned pname = toInt32(info[0], exceptionState); 417 unsigned pname;
413 if (exceptionState.throwIfNeeded()) 418 {
414 return; 419 v8::TryCatch block;
420 V8RethrowTryCatchScope rethrow(block);
421 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[0], exception State), exceptionState);
422 }
415 WebGLGetInfo args = context->getParameter(pname); 423 WebGLGetInfo args = context->getParameter(pname);
416 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); 424 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
417 } 425 }
418 426
419 void V8WebGLRenderingContext::getProgramParameterMethodCustom(const v8::Function CallbackInfo<v8::Value>& info) 427 void V8WebGLRenderingContext::getProgramParameterMethodCustom(const v8::Function CallbackInfo<v8::Value>& info)
420 { 428 {
421 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getProgramP arameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 429 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getProgramP arameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
422 if (info.Length() != 2) { 430 if (info.Length() != 2) {
423 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length())); 431 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
424 exceptionState.throwIfNeeded(); 432 exceptionState.throwIfNeeded();
425 return; 433 return;
426 } 434 }
427 435
428 const int programArgumentIndex = 0;
429 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er()); 436 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
430 if (info.Length() > 0 && !isUndefinedOrNull(info[programArgumentIndex]) && ! V8WebGLProgram::hasInstance(info[programArgumentIndex], info.GetIsolate())) { 437 WebGLProgram* program;
431 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(programArgumentIndex + 1, "WebGLProgram")); 438 unsigned pname;
432 exceptionState.throwIfNeeded(); 439 {
433 return; 440 v8::TryCatch block;
441 V8RethrowTryCatchScope rethrow(block);
442 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram: :hasInstance(info[0], info.GetIsolate())) {
443 exceptionState.throwTypeError("parameter 1 is not of type 'WebGLProg ram'.");
444 exceptionState.throwIfNeeded();
445 return;
446 }
447 TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toNativeWithTypeCheck(in fo.GetIsolate(), info[0]));
448 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exception State), exceptionState);
434 } 449 }
435 WebGLProgram* program = V8WebGLProgram::toNativeWithTypeCheck(info.GetIsolat e(), info[programArgumentIndex]);
436 unsigned pname = toInt32(info[1], exceptionState);
437 if (exceptionState.throwIfNeeded())
438 return;
439 WebGLGetInfo args = context->getProgramParameter(program, pname); 450 WebGLGetInfo args = context->getProgramParameter(program, pname);
440 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); 451 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
441 } 452 }
442 453
443 void V8WebGLRenderingContext::getRenderbufferParameterMethodCustom(const v8::Fun ctionCallbackInfo<v8::Value>& info) 454 void V8WebGLRenderingContext::getRenderbufferParameterMethodCustom(const v8::Fun ctionCallbackInfo<v8::Value>& info)
444 { 455 {
445 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getRenderbu fferParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 456 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getRenderbu fferParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
446 getObjectParameter(info, kRenderbuffer, exceptionState); 457 getObjectParameter(info, kRenderbuffer, exceptionState);
447 } 458 }
448 459
449 void V8WebGLRenderingContext::getShaderParameterMethodCustom(const v8::FunctionC allbackInfo<v8::Value>& info) 460 void V8WebGLRenderingContext::getShaderParameterMethodCustom(const v8::FunctionC allbackInfo<v8::Value>& info)
450 { 461 {
451 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getShaderPa rameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 462 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getShaderPa rameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
452 if (info.Length() != 2) { 463 if (info.Length() != 2) {
453 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length())); 464 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
454 exceptionState.throwIfNeeded(); 465 exceptionState.throwIfNeeded();
455 return; 466 return;
456 } 467 }
457 468
458 const int shaderArgumentIndex = 0;
459 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er()); 469 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
460 if (info.Length() > 0 && !isUndefinedOrNull(info[shaderArgumentIndex]) && !V 8WebGLShader::hasInstance(info[shaderArgumentIndex], info.GetIsolate())) { 470 WebGLShader* shader;
461 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(shaderArgumentIndex + 1, "WebGLShader")); 471 unsigned pname;
462 exceptionState.throwIfNeeded(); 472 {
463 return; 473 v8::TryCatch block;
474 V8RethrowTryCatchScope rethrow(block);
475 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLShader:: hasInstance(info[0], info.GetIsolate())) {
476 exceptionState.throwTypeError("parameter 1 is not of type 'WebGLShad er'.");
477 exceptionState.throwIfNeeded();
478 return;
479 }
480 TONATIVE_VOID_INTERNAL(shader, V8WebGLShader::toNativeWithTypeCheck(info .GetIsolate(), info[0]));
481 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exception State), exceptionState);
464 } 482 }
465 WebGLShader* shader = V8WebGLShader::toNativeWithTypeCheck(info.GetIsolate() , info[shaderArgumentIndex]);
466 unsigned pname = toInt32(info[1], exceptionState);
467 if (exceptionState.throwIfNeeded())
468 return;
469 WebGLGetInfo args = context->getShaderParameter(shader, pname); 483 WebGLGetInfo args = context->getShaderParameter(shader, pname);
470 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); 484 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
471 } 485 }
472 486
473 void V8WebGLRenderingContext::getTexParameterMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info) 487 void V8WebGLRenderingContext::getTexParameterMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
474 { 488 {
475 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getTexParam eter", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 489 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getTexParam eter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
476 getObjectParameter(info, kTexture, exceptionState); 490 getObjectParameter(info, kTexture, exceptionState);
477 } 491 }
478 492
479 void V8WebGLRenderingContext::getUniformMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info) 493 void V8WebGLRenderingContext::getUniformMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
480 { 494 {
481 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getUniform" , "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 495 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getUniform" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
482 if (info.Length() != 2) { 496 if (info.Length() != 2) {
483 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length())); 497 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
484 exceptionState.throwIfNeeded(); 498 exceptionState.throwIfNeeded();
485 return; 499 return;
486 } 500 }
487 501
488 const int programArgumentIndex = 0;
489 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er()); 502 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
490 if (info.Length() > 0 && !isUndefinedOrNull(info[programArgumentIndex]) && ! V8WebGLProgram::hasInstance(info[programArgumentIndex], info.GetIsolate())) { 503 WebGLProgram* program;
491 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(programArgumentIndex + 1, "WebGLProgram")); 504 WebGLUniformLocation* location;
492 exceptionState.throwIfNeeded(); 505 {
493 return; 506 v8::TryCatch block;
507 V8RethrowTryCatchScope rethrow(block);
508 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram: :hasInstance(info[0], info.GetIsolate())) {
509 throwTypeError(ExceptionMessages::failedToExecute("getUniform", "Web GLRenderingContext", "parameter 1 is not of type 'WebGLProgram'."), info.GetIsol ate());
510 return;
511 }
512 TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toNativeWithTypeCheck(in fo.GetIsolate(), info[0]));
513 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !V8WebGLUniformL ocation::hasInstance(info[1], info.GetIsolate())) {
514 throwTypeError(ExceptionMessages::failedToExecute("getUniform", "Web GLRenderingContext", "parameter 2 is not of type 'WebGLUniformLocation'."), info .GetIsolate());
515 return;
516 }
517 TONATIVE_VOID_INTERNAL(location, V8WebGLUniformLocation::toNativeWithTyp eCheck(info.GetIsolate(), info[1]));
494 } 518 }
495 WebGLProgram* program = V8WebGLProgram::toNativeWithTypeCheck(info.GetIsolat e(), info[programArgumentIndex]);
496
497 const int uniformArgumentIndex = 1;
498 if (info.Length() > 1 && !isUndefinedOrNull(info[uniformArgumentIndex]) && ! V8WebGLUniformLocation::hasInstance(info[uniformArgumentIndex], info.GetIsolate( ))) {
499 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(uniformArgumentIndex + 1, "WebGLUniformLocation"));
500 exceptionState.throwIfNeeded();
501 return;
502 }
503 const int uniformLocationArgumentIndex = 1;
504 WebGLUniformLocation* location = toWebGLUniformLocation(info[uniformLocation ArgumentIndex], info.GetIsolate());
505
506 WebGLGetInfo args = context->getUniform(program, location); 519 WebGLGetInfo args = context->getUniform(program, location);
507 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate())); 520 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
508 } 521 }
509 522
510 void V8WebGLRenderingContext::getVertexAttribMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info) 523 void V8WebGLRenderingContext::getVertexAttribMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
511 { 524 {
512 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getVertexAt trib", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 525 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getVertexAt trib", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
513 getObjectParameter(info, kVertexAttrib, exceptionState); 526 getObjectParameter(info, kVertexAttrib, exceptionState);
514 } 527 }
515 528
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 vertexAttribAndUniformHelperf(info, kVertexAttrib3v, exceptionState); 855 vertexAttribAndUniformHelperf(info, kVertexAttrib3v, exceptionState);
843 } 856 }
844 857
845 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info) 858 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
846 { 859 {
847 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri b4fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate()); 860 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri b4fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
848 vertexAttribAndUniformHelperf(info, kVertexAttrib4v, exceptionState); 861 vertexAttribAndUniformHelperf(info, kVertexAttrib4v, exceptionState);
849 } 862 }
850 863
851 } // namespace WebCore 864 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698