Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Jul 13, 2020
1 parent ca117af commit 7b0cef5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 6 additions & 1 deletion polyfills/File/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

// File ()
// https://w3c.github.io/FileAPI/#file-section
var FilePolyfill = function FilePolyfill(fileBits, fileName, options) {
var FilePolyfill = function FilePolyfill(fileBits, fileName) {
// 1. If NewTarget is undefined, throw a TypeError exception.
if (!(this instanceof File)) {
throw new TypeError('Failed to construct \'File\': Please use the \'new\' operator, this DOM object constructor cannot be called as a function.');
Expand All @@ -53,6 +53,11 @@
// Let n be a new string of the same size as the fileName argument to the constructor. Copy every character from fileName to n, replacing any "/" character (U+002F SOLIDUS) with a ":" (U+003A COLON).
var n = fileName.toString().replace(/\//g, ':');

var options;
if (2 < arguments.length) {
options = arguments[2];
}

var file;
if (_hasNativeFileWithWorkingConstructor) {
var file = new NativeFile(fileBits, n, options);
Expand Down
22 changes: 15 additions & 7 deletions polyfills/File/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ it('is a function', function () {
});

it('has correct arity', function () {
proclaim.arity(File, 0);
proclaim.arity(File, 2);
});

it('has correct name', function () {
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('File', function() {
// The name constructor param takes just about anything
// Make sure we match native behaviour.
var c = new File([], {});
proclaim.equal(c.name, '{}');
proclaim.equal(c.name, '[object Object]');

var d = new File([], 5);
proclaim.equal(d.name, '5');
Expand All @@ -52,20 +52,28 @@ describe('File', function() {
}
var e = new File([], eStringer);
proclaim.equal(e.name, 'stringer');

// 4.1.2 https://w3c.github.io/FileAPI/#file-constructor
// Let n be a new string of the same size as the fileName argument to the constructor. Copy every character from fileName to n, replacing any "/" character (U+002F SOLIDUS) with a ":" (U+003A COLON).
var f = new File([], '/alpha//beta/');
proclaim.equal(f.name, ":alpha::beta:");
});

// https://bugs.chromium.org/p/chromium/issues/detail?id=1105171
// it("implements .name escaping", function () {
// // 4.1.2 https://w3c.github.io/FileAPI/#file-constructor
// // Let n be a new string of the same size as the fileName argument to the constructor.
// // Copy every character from fileName to n, replacing any "/" character (U+002F SOLIDUS) with a ":" (U+003A COLON).
// var f = new File([], '/alpha//beta/');
// proclaim.equal(f.name, ":alpha::beta:");
// });

it("implements .lastModified", function () {
// set "now" so that we can compare later
var now = new Date();

var a = new File([], '', {lastModified: 100});
proclaim.equal(a.lastModified, 100);

// Hard to get a fixed number without passing an exact value for lastModified
// Just checking if it is a number
var b = new File([], 'beta');
proclaim.equal(typeof b.lastModified, 'number');
proclaim.ok(now < b.lastModified);
});
});

0 comments on commit 7b0cef5

Please sign in to comment.