Bug 103012 - [V8] Remove return values of macros in V8BindingMacros.h
Summary: [V8] Remove return values of macros in V8BindingMacros.h
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-21 20:14 PST by Kentaro Hara
Modified: 2013-05-02 11:48 PDT (History)
5 users (show)

See Also:


Attachments
Patch (4.77 KB, patch)
2012-11-21 20:17 PST, Kentaro Hara
haraken: review-
webkit.review.bot: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kentaro Hara 2012-11-21 20:14:10 PST
No one uses return values of EXCEPTION_BLOCK() and its friends. We can remove the return values of the macros.

In follow-up patches, I will change these macros to inline methods and optimize the methods by removing redundant TryCatch allocations.
Comment 1 Kentaro Hara 2012-11-21 20:17:49 PST
Created attachment 175574 [details]
Patch
Comment 2 WebKit Review Bot 2012-11-22 02:39:26 PST
Comment on attachment 175574 [details]
Patch

Attachment 175574 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/14950331

New failing tests:
inspector/console/alert-toString-exception.html
fast/workers/worker-constructor.html
fast/workers/storage/execute-sql-args-sync.html
fast/workers/storage/open-database-inputs-sync.html
fast/workers/storage/execute-sql-args-worker.html
storage/websql/execute-sql-args.html
Comment 3 Kentaro Hara 2012-11-22 05:26:30 PST
Comment on attachment 175574 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175574&action=review

> Source/WebCore/bindings/v8/V8BindingMacros.h:-59
> -        return v8::Undefined();

Oh, removing 'v8::Undefined()' is fine but removing 'return' is not fine here.

Either way it looks like I need to think about a whole plan of EXCEPTION_BLOCK()s refactoring before making ad-hoc improvements.

My goal would be implementing the following methods:

double v8ValueToNumber(Handle<Value> value) {
  if (value->IsNumber())
    return value->NumberValue();
  v8::TryCatch block;
  double d = value->NumberValue();
  if (block.HasCaught())
    block.ReThrow();
  return d;
}

double v8ValueToInt32(Handle<Value> value) {
  ...;
}
Comment 4 Adam Barth 2012-11-22 09:05:15 PST
> My goal would be implementing the following methods:
> 
> double v8ValueToNumber(Handle<Value> value) {
>   if (value->IsNumber())
>     return value->NumberValue();
>   v8::TryCatch block;
>   double d = value->NumberValue();
>   if (block.HasCaught())
>     block.ReThrow();

What's the point of catching the exception just to re-throw it?

>   return d;

How does the caller know that there was an exception?  If there was an exception, the caller should return early (e.g., and not process further arguments).

Is there a reason to have a TryCatch block per argument?  I wonder if we can have just one for all the arguments.  We could declare it up front and each argument would do something like

v8::TryCatch block;
String foo = v8ValueToString(args[0]);
if (block.HasCaught()) {
    block.ReThrow();
    return v8::Undefined(args.GetIsolate());
}
double foo = v8ValueToNumber(args[1]);
if (block.HasCaught()) {
    block.ReThrow();
    return v8::Undefined(args.GetIsolate());
}

We might need to get more fancy and create the block lazily (to avoid the overhead of creating one---we should perf test before doing this):

OwnPtr<v8::TryCatch> block;
String foo = v8ValueToString(args[0], block);
if (block && block->HasCaught()) {
    block->ReThrow();
    return v8::Undefined(args.GetIsolate(), block);
}
double foo = v8ValueToNumber(args[1]);
if (block && block->HasCaught()) {
    block->ReThrow();
    return v8::Undefined(args.GetIsolate());
}

Even better might be a way to ask the isolate or the context (whichever is appropriate) if there is a pending exception without needing to create a TryCatch (given that we're just going to re-throw the exception anyway).
Comment 5 Adam Barth 2012-11-22 09:05:52 PST
> double foo = v8ValueToNumber(args[1]);

This should have been

double foo = v8ValueToNumber(args[1], block);

in the last example.
Comment 6 Anders Carlsson 2013-05-02 11:48:19 PDT
V8 is gone from WebKit.