Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
noVNC
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
noVNC
Commits
2930403a
Commit
2930403a
authored
Sep 30, 2014
by
Solly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #397 from kanaka/refactor/use-object-defineproperty
Make Utils.js use Object.define to modify Array
parents
58529d34
f9fd0313
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
61 deletions
+62
-61
util.js
include/util.js
+62
-61
No files found.
include/util.js
View file @
2930403a
...
@@ -17,72 +17,75 @@ var Util = {};
...
@@ -17,72 +17,75 @@ var Util = {};
* Make arrays quack
* Make arrays quack
*/
*/
Array
.
prototype
.
push8
=
function
(
num
)
{
var
addFunc
=
function
(
cl
,
name
,
func
)
{
if
(
!
cl
.
prototype
[
name
])
{
Object
.
defineProperty
(
cl
.
prototype
,
name
,
{
enumerable
:
false
,
value
:
func
});
}
};
addFunc
(
Array
,
'push8'
,
function
(
num
)
{
"use strict"
;
"use strict"
;
this
.
push
(
num
&
0xFF
);
this
.
push
(
num
&
0xFF
);
};
}
)
;
Array
.
prototype
.
push16
=
function
(
num
)
{
addFunc
(
Array
,
'push16'
,
function
(
num
)
{
"use strict"
;
"use strict"
;
this
.
push
((
num
>>
8
)
&
0xFF
,
this
.
push
((
num
>>
8
)
&
0xFF
,
num
&
0xFF
);
num
&
0xFF
);
};
});
Array
.
prototype
.
push32
=
function
(
num
)
{
addFunc
(
Array
,
'push32'
,
function
(
num
)
{
"use strict"
;
"use strict"
;
this
.
push
((
num
>>
24
)
&
0xFF
,
this
.
push
((
num
>>
24
)
&
0xFF
,
(
num
>>
16
)
&
0xFF
,
(
num
>>
16
)
&
0xFF
,
(
num
>>
8
)
&
0xFF
,
(
num
>>
8
)
&
0xFF
,
num
&
0xFF
);
num
&
0xFF
);
};
}
)
;
// IE does not support map (even in IE9)
// IE does not support map (even in IE9)
//This prototype is provided by the Mozilla foundation and
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if
(
!
Array
.
prototype
.
map
)
{
addFunc
(
Array
,
'map'
,
function
(
fun
/*, thisp*/
)
{
Array
.
prototype
.
map
=
function
(
fun
/*, thisp*/
)
{
"use strict"
;
"use strict"
;
var
len
=
this
.
length
;
var
len
=
this
.
length
;
if
(
typeof
fun
!=
"function"
)
{
if
(
typeof
fun
!=
"function"
)
{
throw
new
TypeError
();
throw
new
TypeError
();
}
}
var
res
=
new
Array
(
len
);
var
res
=
new
Array
(
len
);
var
thisp
=
arguments
[
1
];
var
thisp
=
arguments
[
1
];
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
if
(
i
in
this
)
{
if
(
i
in
this
)
{
res
[
i
]
=
fun
.
call
(
thisp
,
this
[
i
],
i
,
this
);
res
[
i
]
=
fun
.
call
(
thisp
,
this
[
i
],
i
,
this
);
}
}
}
}
return
res
;
return
res
;
};
});
}
// IE <9 does not support indexOf
// IE <9 does not support indexOf
//This prototype is provided by the Mozilla foundation and
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if
(
!
Array
.
prototype
.
indexOf
)
{
addFunc
(
Array
,
'indexOf'
,
function
(
elt
/*, from*/
)
{
Array
.
prototype
.
indexOf
=
function
(
elt
/*, from*/
)
{
"use strict"
;
"use strict"
;
var
len
=
this
.
length
>>>
0
;
var
len
=
this
.
length
>>>
0
;
var
from
=
Number
(
arguments
[
1
])
||
0
;
from
=
(
from
<
0
)
?
Math
.
ceil
(
from
)
:
Math
.
floor
(
from
);
if
(
from
<
0
)
{
from
+=
len
;
}
for
(;
from
<
len
;
from
++
)
{
var
from
=
Number
(
arguments
[
1
])
||
0
;
if
(
from
in
this
&&
from
=
(
from
<
0
)
?
Math
.
ceil
(
from
)
:
Math
.
floor
(
from
);
this
[
from
]
===
elt
)
{
if
(
from
<
0
)
{
return
from
;
from
+=
len
;
}
}
for
(;
from
<
len
;
from
++
)
{
if
(
from
in
this
&&
this
[
from
]
===
elt
)
{
return
from
;
}
}
return
-
1
;
}
}
;
return
-
1
;
}
}
);
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if
(
!
Object
.
keys
)
{
if
(
!
Object
.
keys
)
{
...
@@ -131,30 +134,28 @@ if (!Object.keys) {
...
@@ -131,30 +134,28 @@ if (!Object.keys) {
//This prototype is provided by the Mozilla foundation and
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if
(
!
Function
.
prototype
.
bind
)
{
addFunc
(
Function
,
'bind'
,
function
(
oThis
)
{
Function
.
prototype
.
bind
=
function
(
oThis
)
{
if
(
typeof
this
!==
"function"
)
{
if
(
typeof
this
!==
"function"
)
{
// closest thing possible to the ECMAScript 5
// closest thing possible to the ECMAScript 5
// internal IsCallable function
// internal IsCallable function
throw
new
TypeError
(
"Function.prototype.bind - "
+
throw
new
TypeError
(
"Function.prototype.bind - "
+
"what is trying to be bound is not callable"
);
"what is trying to be bound is not callable"
);
}
}
var
aArgs
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
),
var
aArgs
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
),
fToBind
=
this
,
fToBind
=
this
,
fNOP
=
function
()
{},
fNOP
=
function
()
{},
fBound
=
function
()
{
fBound
=
function
()
{
return
fToBind
.
apply
(
this
instanceof
fNOP
&&
oThis
?
this
return
fToBind
.
apply
(
this
instanceof
fNOP
&&
oThis
?
this
:
oThis
,
:
oThis
,
aArgs
.
concat
(
Array
.
prototype
.
slice
.
call
(
arguments
)));
aArgs
.
concat
(
Array
.
prototype
.
slice
.
call
(
arguments
)));
};
};
fNOP
.
prototype
=
this
.
prototype
;
fNOP
.
prototype
=
this
.
prototype
;
fBound
.
prototype
=
new
fNOP
();
fBound
.
prototype
=
new
fNOP
();
return
fBound
;
return
fBound
;
};
});
}
//
//
// requestAnimationFrame shim with setTimeout fallback
// requestAnimationFrame shim with setTimeout fallback
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment