Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update substr calls to substring #4276

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/graphics/program-lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function collectAttribs(vsCode) {
if (found > 0 && vsCode[found - 1] === "/") break;
const endOfLine = vsCode.indexOf(';', found);
const startOfAttribName = vsCode.lastIndexOf(' ', endOfLine);
const attribName = vsCode.substr(startOfAttribName + 1, endOfLine - (startOfAttribName + 1));
const attribName = vsCode.substring(startOfAttribName + 1, endOfLine);

const semantic = attrib2Semantic[attribName];
if (semantic !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/shader-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ShaderInput {
this.version = new Version();

// custom data type for arrays
if (name.substr(name.length - 3) === "[0]") {
if (name.substring(name.length - 3) === "[0]") {
switch (type) {
case UNIFORMTYPE_FLOAT: type = UNIFORMTYPE_FLOATARRAY; break;
case UNIFORMTYPE_VEC2: type = UNIFORMTYPE_VEC2ARRAY; break;
Expand Down
5 changes: 3 additions & 2 deletions src/polyfill/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defineProtoFunc(String, 'includes', function(search, start) {
});

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill
defineProtoFunc(String, 'startsWith', function(search, pos) {
return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
defineProtoFunc(String, 'startsWith', function(search, rawPos) {
var pos = rawPos > 0 ? rawPos|0 : 0;
return this.substring(pos, pos + search.length) === search;
Comment on lines +26 to +28
Copy link
Collaborator

@kungfooman kungfooman May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defineProtoFunc(String, 'startsWith', function(search, rawPos) {
var pos = rawPos > 0 ? rawPos|0 : 0;
return this.substring(pos, pos + search.length) === search;
defineProtoFunc(String, 'startsWith', function(search, pos) {
pos = pos > 0 ? pos|0 : 0;
return this.substring(pos, pos + search.length) === search;

(removing var while reusing pos variable)

Copy link
Contributor Author

@willeastcott willeastcott May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this code can be tweaked but I'm just updating what's here to the linked Polyfill on MDN. I'd rather keep this in sync with that.

});
10 changes: 5 additions & 5 deletions src/resources/untar.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ function UntarScope(isWorker) {
const headers = asciiDecoder.decode(headersDataView);
this._bytesRead += 512;

let name = headers.substr(0, 100).replace(/\0/g, '');
const ustarFormat = headers.substr(257, 6);
const size = parseInt(headers.substr(124, 12), 8);
const type = headers.substr(156, 1);
let name = headers.substring(0, 100).replace(/\0/g, '');
const ustarFormat = headers.substring(257, 263);
const size = parseInt(headers.substring(124, 136), 8);
const type = headers.substring(156, 157);
const start = this._bytesRead;
let url = null;

Expand Down Expand Up @@ -171,7 +171,7 @@ function UntarScope(isWorker) {
}

if (ustarFormat.indexOf('ustar') !== -1) {
const namePrefix = headers.substr(345, 155).replace(/\0/g, '');
const namePrefix = headers.substring(345, 500).replace(/\0/g, '');

if (namePrefix.length > 0) {
name = namePrefix.trim() + name.trim();
Expand Down