Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
daf5c646
Commit
daf5c646
authored
Nov 28, 2014
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1693 from hypothesis/refactor-chrome-ext
Restructure Chrome Extension
parents
e4be6357
70c98a9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
212 additions
and
0 deletions
+212
-0
bind.js
h/static/scripts/vendor/bind.js
+26
-0
promise.js
h/static/scripts/vendor/promise.js
+186
-0
No files found.
h/static/scripts/vendor/bind.js
0 → 100644
View file @
daf5c646
// Source: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
if
(
!
Function
.
prototype
.
bind
)
{
Function
.
prototype
.
bind
=
function
(
oThis
)
{
if
(
typeof
this
!==
"function"
)
{
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw
new
TypeError
(
"Function.prototype.bind - what is trying to be bound is not callable"
);
}
var
aArgs
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
),
fToBind
=
this
,
fNOP
=
function
()
{},
fBound
=
function
()
{
return
fToBind
.
apply
(
this
instanceof
fNOP
&&
oThis
?
this
:
oThis
,
aArgs
.
concat
(
Array
.
prototype
.
slice
.
call
(
arguments
)));
};
fNOP
.
prototype
=
this
.
prototype
;
fBound
.
prototype
=
new
fNOP
();
return
fBound
;
};
}
h/static/scripts/vendor/promise.js
0 → 100644
View file @
daf5c646
(
function
()
{
var
root
;
if
(
typeof
window
===
'object'
&&
window
)
{
root
=
window
;
}
else
{
root
=
global
;
}
if
(
typeof
module
!==
'undefined'
&&
module
.
exports
)
{
module
.
exports
=
root
.
Promise
?
root
.
Promise
:
Promise
;
}
else
if
(
!
root
.
Promise
)
{
root
.
Promise
=
Promise
;
}
// Use polyfill for setImmediate for performance gains
var
asap
=
root
.
setImmediate
||
function
(
fn
)
{
setTimeout
(
fn
,
1
);
};
// Polyfill for Function.prototype.bind
function
bind
(
fn
,
thisArg
)
{
return
function
()
{
fn
.
apply
(
thisArg
,
arguments
);
}
}
var
isArray
=
Array
.
isArray
||
function
(
value
)
{
return
Object
.
prototype
.
toString
.
call
(
value
)
===
"[object Array]"
};
function
Promise
(
fn
)
{
if
(
typeof
this
!==
'object'
)
throw
new
TypeError
(
'Promises must be constructed via new'
);
if
(
typeof
fn
!==
'function'
)
throw
new
TypeError
(
'not a function'
);
this
.
_state
=
null
;
this
.
_value
=
null
;
this
.
_deferreds
=
[]
doResolve
(
fn
,
bind
(
resolve
,
this
),
bind
(
reject
,
this
))
}
function
handle
(
deferred
)
{
var
me
=
this
;
if
(
this
.
_state
===
null
)
{
this
.
_deferreds
.
push
(
deferred
);
return
}
asap
(
function
()
{
var
cb
=
me
.
_state
?
deferred
.
onFulfilled
:
deferred
.
onRejected
if
(
cb
===
null
)
{
(
me
.
_state
?
deferred
.
resolve
:
deferred
.
reject
)(
me
.
_value
);
return
;
}
var
ret
;
try
{
ret
=
cb
(
me
.
_value
);
}
catch
(
e
)
{
deferred
.
reject
(
e
);
return
;
}
deferred
.
resolve
(
ret
);
})
}
function
resolve
(
newValue
)
{
try
{
//Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
if
(
newValue
===
this
)
throw
new
TypeError
(
'A promise cannot be resolved with itself.'
);
if
(
newValue
&&
(
typeof
newValue
===
'object'
||
typeof
newValue
===
'function'
))
{
var
then
=
newValue
.
then
;
if
(
typeof
then
===
'function'
)
{
doResolve
(
bind
(
then
,
newValue
),
bind
(
resolve
,
this
),
bind
(
reject
,
this
));
return
;
}
}
this
.
_state
=
true
;
this
.
_value
=
newValue
;
finale
.
call
(
this
);
}
catch
(
e
)
{
reject
.
call
(
this
,
e
);
}
}
function
reject
(
newValue
)
{
this
.
_state
=
false
;
this
.
_value
=
newValue
;
finale
.
call
(
this
);
}
function
finale
()
{
for
(
var
i
=
0
,
len
=
this
.
_deferreds
.
length
;
i
<
len
;
i
++
)
{
handle
.
call
(
this
,
this
.
_deferreds
[
i
]);
}
this
.
_deferreds
=
null
;
}
function
Handler
(
onFulfilled
,
onRejected
,
resolve
,
reject
){
this
.
onFulfilled
=
typeof
onFulfilled
===
'function'
?
onFulfilled
:
null
;
this
.
onRejected
=
typeof
onRejected
===
'function'
?
onRejected
:
null
;
this
.
resolve
=
resolve
;
this
.
reject
=
reject
;
}
/**
* Take a potentially misbehaving resolver function and make sure
* onFulfilled and onRejected are only called once.
*
* Makes no guarantees about asynchrony.
*/
function
doResolve
(
fn
,
onFulfilled
,
onRejected
)
{
var
done
=
false
;
try
{
fn
(
function
(
value
)
{
if
(
done
)
return
;
done
=
true
;
onFulfilled
(
value
);
},
function
(
reason
)
{
if
(
done
)
return
;
done
=
true
;
onRejected
(
reason
);
})
}
catch
(
ex
)
{
if
(
done
)
return
;
done
=
true
;
onRejected
(
ex
);
}
}
Promise
.
prototype
[
'catch'
]
=
function
(
onRejected
)
{
return
this
.
then
(
null
,
onRejected
);
};
Promise
.
prototype
.
then
=
function
(
onFulfilled
,
onRejected
)
{
var
me
=
this
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
handle
.
call
(
me
,
new
Handler
(
onFulfilled
,
onRejected
,
resolve
,
reject
));
})
};
Promise
.
all
=
function
()
{
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
.
length
===
1
&&
isArray
(
arguments
[
0
])
?
arguments
[
0
]
:
arguments
);
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
args
.
length
===
0
)
return
resolve
([]);
var
remaining
=
args
.
length
;
function
res
(
i
,
val
)
{
try
{
if
(
val
&&
(
typeof
val
===
'object'
||
typeof
val
===
'function'
))
{
var
then
=
val
.
then
;
if
(
typeof
then
===
'function'
)
{
then
.
call
(
val
,
function
(
val
)
{
res
(
i
,
val
)
},
reject
);
return
;
}
}
args
[
i
]
=
val
;
if
(
--
remaining
===
0
)
{
resolve
(
args
);
}
}
catch
(
ex
)
{
reject
(
ex
);
}
}
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
)
{
res
(
i
,
args
[
i
]);
}
});
};
Promise
.
resolve
=
function
(
value
)
{
if
(
value
&&
typeof
value
===
'object'
&&
value
.
constructor
===
Promise
)
{
return
value
;
}
return
new
Promise
(
function
(
resolve
)
{
resolve
(
value
);
});
};
Promise
.
reject
=
function
(
value
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
reject
(
value
);
});
};
Promise
.
race
=
function
(
values
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
for
(
var
i
=
0
,
len
=
values
.
length
;
i
<
len
;
i
++
)
{
values
[
i
].
then
(
resolve
,
reject
);
}
});
};
})();
\ No newline at end of file
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