Closed Bug 590672 Opened 14 years ago Closed 14 years ago

treat ArrayBuffer() and SomeArrayType() as (0)

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: vlad, Assigned: vlad)

References

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

We shouldn't be throwing on no args, should implicitly treat it as 0.  This isn't super useful, but is more js-like.
Attached patch treat () as (0)Splinter Review
Pretty simple patch.  Just treats argc == 0 as if a 0 int was passed as the first arg.
Attachment #469201 - Flags: review?(jorendorff)
Comment on attachment 469201 [details] [diff] [review]
treat () as (0)

Stealing.
Attachment #469201 - Flags: review?(jorendorff) → review?(shaver)
Comment on attachment 469201 [details] [diff] [review]
treat () as (0)

># HG changeset patch
># Parent b6b28598c817ad79848e69f1d967b8a6770b3512
>@@ -745,20 +742,17 @@ class TypedArrayTemplate
> 
>         ThisTypeArray *tarray = 0;
> 
>-        // must have at least one arg
>-        if (argc == 0) {
>-            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
>-                                 JSMSG_TYPED_ARRAY_BAD_ARGS);
>-            return false;
>-        }
>+        // figure out the type of the first argument;
>+        // no args is treated like an int arg of 0.
>+        if (argc == 0 || argv[0].isInt32()) {
>+            int32 len = 0;
> 
>-        // figure out the type of the first argument
>-        if (argv[0].isInt32()) {
>-            int32 len = argv[0].toInt32();
>+            if (argc > 0)
>+                len = argv[0].toInt32();
>+

A little weird to have an == test and then a > test that follows for the same sort of distinction.

Is there really much that's common in these blocks?

r=shaver with clarifying reformat, or if you decide not to; I can go either way, though would prefer "!= 0" to "> 0" a fair bit.
Attachment #469201 - Flags: review?(shaver) → review+
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: