Bug 126004 - Implement ArrayBuffer.isView
Summary: Implement ArrayBuffer.isView
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-12-19 11:49 PST by Brent Fulgham
Modified: 2013-12-19 16:39 PST (History)
4 users (show)

See Also:


Attachments
Patch (3.71 KB, patch)
2013-12-19 15:25 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (4.16 KB, patch)
2013-12-19 16:30 PST, Brent Fulgham
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2013-12-19 11:49:11 PST
We need an implementation of ArrayBuffer.isView, added to the ECMA specification as of the May 14, 2013 draft:

15.13.5.4.2 ArrayBuffer.isView ( arg )
The isView function takes one argument arg, and performs the following steps are taken:
1. If Type(arg) is not Object, return false.
2. If arg is an exotic Array object, then return true.
3. If arg has a [[ViewedArrayBuffer]] internal data property, then return true.
4. Return false.

This is needed to fully comply with WebGL requirements.
Comment 1 Brent Fulgham 2013-12-19 15:22:44 PST
<rdar://problem/15201822>
Comment 2 Brent Fulgham 2013-12-19 15:25:13 PST
Created attachment 219690 [details]
Patch
Comment 3 Oliver Hunt 2013-12-19 15:52:08 PST
Comment on attachment 219690 [details]
Patch

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

Almost there :)

> Source/JavaScriptCore/runtime/JSArrayBufferConstructor.cpp:56
> +    putDirectNativeFunction(vm, globalObject(), makeIdentifier(vm, ("isView")), 1, arrayBufferFuncIsView, NoIntrinsic, DontEnum |Function);

JSC_NATIVE_FUNCTION(vm.propertyNames->isView, arrayBufferFuncIsView, DontEnum, 1);

Add isView to CommonIdentifiers
Comment 4 Brent Fulgham 2013-12-19 16:06:18 PST
Comment on attachment 219690 [details]
Patch

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

>> Source/JavaScriptCore/runtime/JSArrayBufferConstructor.cpp:56
>> +    putDirectNativeFunction(vm, globalObject(), makeIdentifier(vm, ("isView")), 1, arrayBufferFuncIsView, NoIntrinsic, DontEnum |Function);
> 
> JSC_NATIVE_FUNCTION(vm.propertyNames->isView, arrayBufferFuncIsView, DontEnum, 1);
> 
> Add isView to CommonIdentifiers

I tried using JSC_NATIVE_FUNCTION, but it assumes "globalObject" is defined in the current scope (except as a function), so the macro gives a syntax error.
Comment 5 Filip Pizlo 2013-12-19 16:10:17 PST
Comment on attachment 219690 [details]
Patch

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

R=me unless Oliver has super strong opinions about that macro.

>>> Source/JavaScriptCore/runtime/JSArrayBufferConstructor.cpp:56
>>> +    putDirectNativeFunction(vm, globalObject(), makeIdentifier(vm, ("isView")), 1, arrayBufferFuncIsView, NoIntrinsic, DontEnum |Function);
>> 
>> JSC_NATIVE_FUNCTION(vm.propertyNames->isView, arrayBufferFuncIsView, DontEnum, 1);
>> 
>> Add isView to CommonIdentifiers
> 
> I tried using JSC_NATIVE_FUNCTION, but it assumes "globalObject" is defined in the current scope (except as a function), so the macro gives a syntax error.

Yeah, other places that use JSC_NATIVE_FUNCTION often have some pro-forma setup like:

JSGlobalObject* globalObject = prototype->globalObjects();

Or whatever is appropriate.

 I don't mind that you're calling putDirectNativeFunction directly.  But, you should add isView to CommonIdentifiers.  Then you'll access it by saying vm.propertyNames->isView.  This isn't a big deal, but it's nice to be consistent.
Comment 6 Brent Fulgham 2013-12-19 16:30:20 PST
Created attachment 219699 [details]
Patch
Comment 7 Brent Fulgham 2013-12-19 16:39:37 PST
Committed r160876: <http://trac.webkit.org/changeset/160876>