code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function resolveDefaultProps(Component, baseProps) {
if (Component && Component.defaultProps) {
var props = assign({}, baseProps);
var defaultProps = Component.defaultProps;
for (var propName in defaultProps) {
if (props[propName] === void 0) {
props[propName] = defaultProps[propName];
}
}
return props;
}
return baseProps;
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
resolveDefaultProps
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderForwardRef(request, task, type, props, ref) {
pushFunctionComponentStackInDEV(task, type.render);
var children = renderWithHooks(request, task, type.render, props, ref);
var hasId = checkDidRenderIdHook();
if (hasId) {
var prevTreeContext = task.treeContext;
var totalChildren = 1;
var index = 0;
task.treeContext = pushTreeContext(prevTreeContext, totalChildren, index);
try {
renderNodeDestructive(request, task, children);
} finally {
task.treeContext = prevTreeContext;
}
} else {
renderNodeDestructive(request, task, children);
}
popComponentStackInDEV(task);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderForwardRef
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderMemo(request, task, type, props, ref) {
var innerType = type.type;
var resolvedProps = resolveDefaultProps(innerType, props);
renderElement(request, task, innerType, resolvedProps, ref);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderMemo
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderContextConsumer(request, task, context, props) {
{
if (context._context === void 0) {
if (context !== context.Consumer) {
if (!hasWarnedAboutUsingContextAsConsumer) {
hasWarnedAboutUsingContextAsConsumer = true;
error("Rendering <Context> directly is not supported and will be removed in a future major release. Did you mean to render <Context.Consumer> instead?");
}
}
} else {
context = context._context;
}
}
var render = props.children;
{
if (typeof render !== "function") {
error("A context consumer was rendered with multiple children, or a child that isn't a function. A context consumer expects a single child that is a function. If you did pass a function, make sure there is no trailing or leading whitespace around it.");
}
}
var newValue = readContext(context);
var newChildren = render(newValue);
renderNodeDestructive(request, task, newChildren);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderContextConsumer
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderContextProvider(request, task, type, props) {
var context = type._context;
var value = props.value;
var children = props.children;
var prevSnapshot;
{
prevSnapshot = task.context;
}
task.context = pushProvider(context, value);
renderNodeDestructive(request, task, children);
task.context = popProvider(context);
{
if (prevSnapshot !== task.context) {
error("Popping the context provider did not return back to the original snapshot. This is a bug in React.");
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderContextProvider
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderLazyComponent(request, task, lazyComponent, props, ref) {
pushBuiltInComponentStackInDEV(task, "Lazy");
var payload = lazyComponent._payload;
var init = lazyComponent._init;
var Component = init(payload);
var resolvedProps = resolveDefaultProps(Component, props);
renderElement(request, task, Component, resolvedProps, ref);
popComponentStackInDEV(task);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderLazyComponent
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderElement(request, task, type, props, ref) {
if (typeof type === "function") {
if (shouldConstruct$1(type)) {
renderClassComponent(request, task, type, props);
return;
} else {
renderIndeterminateComponent(request, task, type, props);
return;
}
}
if (typeof type === "string") {
renderHostElement(request, task, type, props);
return;
}
switch (type) {
case REACT_LEGACY_HIDDEN_TYPE:
case REACT_DEBUG_TRACING_MODE_TYPE:
case REACT_STRICT_MODE_TYPE:
case REACT_PROFILER_TYPE:
case REACT_FRAGMENT_TYPE: {
renderNodeDestructive(request, task, props.children);
return;
}
case REACT_SUSPENSE_LIST_TYPE: {
pushBuiltInComponentStackInDEV(task, "SuspenseList");
renderNodeDestructive(request, task, props.children);
popComponentStackInDEV(task);
return;
}
case REACT_SCOPE_TYPE: {
throw new Error("ReactDOMServer does not yet support scope components.");
}
case REACT_SUSPENSE_TYPE: {
{
renderSuspenseBoundary(request, task, props);
}
return;
}
}
if (typeof type === "object" && type !== null) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE: {
renderForwardRef(request, task, type, props, ref);
return;
}
case REACT_MEMO_TYPE: {
renderMemo(request, task, type, props, ref);
return;
}
case REACT_PROVIDER_TYPE: {
renderContextProvider(request, task, type, props);
return;
}
case REACT_CONTEXT_TYPE: {
renderContextConsumer(request, task, type, props);
return;
}
case REACT_LAZY_TYPE: {
renderLazyComponent(request, task, type, props);
return;
}
}
}
var info = "";
{
if (type === void 0 || typeof type === "object" && type !== null && Object.keys(type).length === 0) {
info += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.";
}
}
throw new Error("Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) " + ("but got: " + (type == null ? type : typeof type) + "." + info));
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderElement
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function validateIterable(iterable, iteratorFn) {
{
if (typeof Symbol === "function" && // $FlowFixMe Flow doesn't know about toStringTag
iterable[Symbol.toStringTag] === "Generator") {
if (!didWarnAboutGenerators) {
error("Using Generators as children is unsupported and will likely yield unexpected results because enumerating a generator mutates it. You may convert it to an array with `Array.from()` or the `[...spread]` operator before rendering. Keep in mind you might need to polyfill these features for older browsers.");
}
didWarnAboutGenerators = true;
}
if (iterable.entries === iteratorFn) {
if (!didWarnAboutMaps) {
error("Using Maps as children is not supported. Use an array of keyed ReactElements instead.");
}
didWarnAboutMaps = true;
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
validateIterable
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderNodeDestructive(request, task, node) {
{
try {
return renderNodeDestructiveImpl(request, task, node);
} catch (x) {
if (typeof x === "object" && x !== null && typeof x.then === "function")
;
else {
lastBoundaryErrorComponentStackDev = lastBoundaryErrorComponentStackDev !== null ? lastBoundaryErrorComponentStackDev : getCurrentStackInDEV();
}
throw x;
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderNodeDestructive
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderNodeDestructiveImpl(request, task, node) {
task.node = node;
if (typeof node === "object" && node !== null) {
switch (node.$$typeof) {
case REACT_ELEMENT_TYPE: {
var element = node;
var type = element.type;
var props = element.props;
var ref = element.ref;
renderElement(request, task, type, props, ref);
return;
}
case REACT_PORTAL_TYPE:
throw new Error("Portals are not currently supported by the server renderer. Render them conditionally so that they only appear on the client render.");
case REACT_LAZY_TYPE: {
var lazyNode = node;
var payload = lazyNode._payload;
var init = lazyNode._init;
var resolvedNode;
{
try {
resolvedNode = init(payload);
} catch (x) {
if (typeof x === "object" && x !== null && typeof x.then === "function") {
pushBuiltInComponentStackInDEV(task, "Lazy");
}
throw x;
}
}
renderNodeDestructive(request, task, resolvedNode);
return;
}
}
if (isArray(node)) {
renderChildrenArray(request, task, node);
return;
}
var iteratorFn = getIteratorFn(node);
if (iteratorFn) {
{
validateIterable(node, iteratorFn);
}
var iterator = iteratorFn.call(node);
if (iterator) {
var step = iterator.next();
if (!step.done) {
var children = [];
do {
children.push(step.value);
step = iterator.next();
} while (!step.done);
renderChildrenArray(request, task, children);
return;
}
return;
}
}
var childString = Object.prototype.toString.call(node);
throw new Error("Objects are not valid as a React child (found: " + (childString === "[object Object]" ? "object with keys {" + Object.keys(node).join(", ") + "}" : childString) + "). If you meant to render a collection of children, use an array instead.");
}
if (typeof node === "string") {
var segment = task.blockedSegment;
segment.lastPushedText = pushTextInstance(task.blockedSegment.chunks, node, request.responseState, segment.lastPushedText);
return;
}
if (typeof node === "number") {
var _segment = task.blockedSegment;
_segment.lastPushedText = pushTextInstance(task.blockedSegment.chunks, "" + node, request.responseState, _segment.lastPushedText);
return;
}
{
if (typeof node === "function") {
error("Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.");
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderNodeDestructiveImpl
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderChildrenArray(request, task, children) {
var totalChildren = children.length;
for (var i = 0; i < totalChildren; i++) {
var prevTreeContext = task.treeContext;
task.treeContext = pushTreeContext(prevTreeContext, totalChildren, i);
try {
renderNode(request, task, children[i]);
} finally {
task.treeContext = prevTreeContext;
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderChildrenArray
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function spawnNewSuspendedTask(request, task, x) {
var segment = task.blockedSegment;
var insertionIndex = segment.chunks.length;
var newSegment = createPendingSegment(
request,
insertionIndex,
null,
segment.formatContext,
// Adopt the parent segment's leading text embed
segment.lastPushedText,
// Assume we are text embedded at the trailing edge
true
);
segment.children.push(newSegment);
segment.lastPushedText = false;
var newTask = createTask(request, task.node, task.blockedBoundary, newSegment, task.abortSet, task.legacyContext, task.context, task.treeContext);
{
if (task.componentStack !== null) {
newTask.componentStack = task.componentStack.parent;
}
}
var ping = newTask.ping;
x.then(ping, ping);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
spawnNewSuspendedTask
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderNode(request, task, node) {
var previousFormatContext = task.blockedSegment.formatContext;
var previousLegacyContext = task.legacyContext;
var previousContext = task.context;
var previousComponentStack = null;
{
previousComponentStack = task.componentStack;
}
try {
return renderNodeDestructive(request, task, node);
} catch (x) {
resetHooksState();
if (typeof x === "object" && x !== null && typeof x.then === "function") {
spawnNewSuspendedTask(request, task, x);
task.blockedSegment.formatContext = previousFormatContext;
task.legacyContext = previousLegacyContext;
task.context = previousContext;
switchContext(previousContext);
{
task.componentStack = previousComponentStack;
}
return;
} else {
task.blockedSegment.formatContext = previousFormatContext;
task.legacyContext = previousLegacyContext;
task.context = previousContext;
switchContext(previousContext);
{
task.componentStack = previousComponentStack;
}
throw x;
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderNode
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function erroredTask(request, boundary, segment, error2) {
var errorDigest = logRecoverableError(request, error2);
if (boundary === null) {
fatalError(request, error2);
} else {
boundary.pendingTasks--;
if (!boundary.forceClientRender) {
boundary.forceClientRender = true;
boundary.errorDigest = errorDigest;
{
captureBoundaryErrorDetailsDev(boundary, error2);
}
if (boundary.parentFlushed) {
request.clientRenderedBoundaries.push(boundary);
}
}
}
request.allPendingTasks--;
if (request.allPendingTasks === 0) {
var onAllReady = request.onAllReady;
onAllReady();
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
erroredTask
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function abortTaskSoft(task) {
var request = this;
var boundary = task.blockedBoundary;
var segment = task.blockedSegment;
segment.status = ABORTED;
finishedTask(request, boundary, segment);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
abortTaskSoft
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function abortTask(task, request, reason) {
var boundary = task.blockedBoundary;
var segment = task.blockedSegment;
segment.status = ABORTED;
if (boundary === null) {
request.allPendingTasks--;
if (request.status !== CLOSED) {
request.status = CLOSED;
if (request.destination !== null) {
close(request.destination);
}
}
} else {
boundary.pendingTasks--;
if (!boundary.forceClientRender) {
boundary.forceClientRender = true;
var _error = reason === void 0 ? new Error("The render was aborted by the server without a reason.") : reason;
boundary.errorDigest = request.onError(_error);
{
var errorPrefix = "The server did not finish this Suspense boundary: ";
if (_error && typeof _error.message === "string") {
_error = errorPrefix + _error.message;
} else {
_error = errorPrefix + String(_error);
}
var previousTaskInDev = currentTaskInDEV;
currentTaskInDEV = task;
try {
captureBoundaryErrorDetailsDev(boundary, _error);
} finally {
currentTaskInDEV = previousTaskInDev;
}
}
if (boundary.parentFlushed) {
request.clientRenderedBoundaries.push(boundary);
}
}
boundary.fallbackAbortableTasks.forEach(function(fallbackTask) {
return abortTask(fallbackTask, request, reason);
});
boundary.fallbackAbortableTasks.clear();
request.allPendingTasks--;
if (request.allPendingTasks === 0) {
var onAllReady = request.onAllReady;
onAllReady();
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
abortTask
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function queueCompletedSegment(boundary, segment) {
if (segment.chunks.length === 0 && segment.children.length === 1 && segment.children[0].boundary === null) {
var childSegment = segment.children[0];
childSegment.id = segment.id;
childSegment.parentFlushed = true;
if (childSegment.status === COMPLETED) {
queueCompletedSegment(boundary, childSegment);
}
} else {
var completedSegments = boundary.completedSegments;
completedSegments.push(segment);
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
queueCompletedSegment
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function finishedTask(request, boundary, segment) {
if (boundary === null) {
if (segment.parentFlushed) {
if (request.completedRootSegment !== null) {
throw new Error("There can only be one root segment. This is a bug in React.");
}
request.completedRootSegment = segment;
}
request.pendingRootTasks--;
if (request.pendingRootTasks === 0) {
request.onShellError = noop$1;
var onShellReady = request.onShellReady;
onShellReady();
}
} else {
boundary.pendingTasks--;
if (boundary.forceClientRender)
;
else if (boundary.pendingTasks === 0) {
if (segment.parentFlushed) {
if (segment.status === COMPLETED) {
queueCompletedSegment(boundary, segment);
}
}
if (boundary.parentFlushed) {
request.completedBoundaries.push(boundary);
}
boundary.fallbackAbortableTasks.forEach(abortTaskSoft, request);
boundary.fallbackAbortableTasks.clear();
} else {
if (segment.parentFlushed) {
if (segment.status === COMPLETED) {
queueCompletedSegment(boundary, segment);
var completedSegments = boundary.completedSegments;
if (completedSegments.length === 1) {
if (boundary.parentFlushed) {
request.partialBoundaries.push(boundary);
}
}
}
}
}
}
request.allPendingTasks--;
if (request.allPendingTasks === 0) {
var onAllReady = request.onAllReady;
onAllReady();
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
finishedTask
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function retryTask(request, task) {
var segment = task.blockedSegment;
if (segment.status !== PENDING) {
return;
}
switchContext(task.context);
var prevTaskInDEV = null;
{
prevTaskInDEV = currentTaskInDEV;
currentTaskInDEV = task;
}
try {
renderNodeDestructive(request, task, task.node);
pushSegmentFinale(segment.chunks, request.responseState, segment.lastPushedText, segment.textEmbedded);
task.abortSet.delete(task);
segment.status = COMPLETED;
finishedTask(request, task.blockedBoundary, segment);
} catch (x) {
resetHooksState();
if (typeof x === "object" && x !== null && typeof x.then === "function") {
var ping = task.ping;
x.then(ping, ping);
} else {
task.abortSet.delete(task);
segment.status = ERRORED;
erroredTask(request, task.blockedBoundary, segment, x);
}
} finally {
{
currentTaskInDEV = prevTaskInDEV;
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
retryTask
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function performWork(request) {
if (request.status === CLOSED) {
return;
}
var prevContext = getActiveContext();
var prevDispatcher = ReactCurrentDispatcher$1.current;
ReactCurrentDispatcher$1.current = Dispatcher;
var prevGetCurrentStackImpl;
{
prevGetCurrentStackImpl = ReactDebugCurrentFrame$1.getCurrentStack;
ReactDebugCurrentFrame$1.getCurrentStack = getCurrentStackInDEV;
}
var prevResponseState = currentResponseState;
setCurrentResponseState(request.responseState);
try {
var pingedTasks = request.pingedTasks;
var i;
for (i = 0; i < pingedTasks.length; i++) {
var task = pingedTasks[i];
retryTask(request, task);
}
pingedTasks.splice(0, i);
if (request.destination !== null) {
flushCompletedQueues(request, request.destination);
}
} catch (error2) {
logRecoverableError(request, error2);
fatalError(request, error2);
} finally {
setCurrentResponseState(prevResponseState);
ReactCurrentDispatcher$1.current = prevDispatcher;
{
ReactDebugCurrentFrame$1.getCurrentStack = prevGetCurrentStackImpl;
}
if (prevDispatcher === Dispatcher) {
switchContext(prevContext);
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
performWork
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushSubtree(request, destination, segment) {
segment.parentFlushed = true;
switch (segment.status) {
case PENDING: {
var segmentID = segment.id = request.nextSegmentId++;
segment.lastPushedText = false;
segment.textEmbedded = false;
return writePlaceholder(destination, request.responseState, segmentID);
}
case COMPLETED: {
segment.status = FLUSHED;
var r = true;
var chunks = segment.chunks;
var chunkIdx = 0;
var children = segment.children;
for (var childIdx = 0; childIdx < children.length; childIdx++) {
var nextChild = children[childIdx];
for (; chunkIdx < nextChild.index; chunkIdx++) {
writeChunk(destination, chunks[chunkIdx]);
}
r = flushSegment(request, destination, nextChild);
}
for (; chunkIdx < chunks.length - 1; chunkIdx++) {
writeChunk(destination, chunks[chunkIdx]);
}
if (chunkIdx < chunks.length) {
r = writeChunkAndReturn(destination, chunks[chunkIdx]);
}
return r;
}
default: {
throw new Error("Aborted, errored or already flushed boundaries should not be flushed again. This is a bug in React.");
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushSubtree
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushSegment(request, destination, segment) {
var boundary = segment.boundary;
if (boundary === null) {
return flushSubtree(request, destination, segment);
}
boundary.parentFlushed = true;
if (boundary.forceClientRender) {
writeStartClientRenderedSuspenseBoundary(destination, request.responseState, boundary.errorDigest, boundary.errorMessage, boundary.errorComponentStack);
flushSubtree(request, destination, segment);
return writeEndClientRenderedSuspenseBoundary(destination, request.responseState);
} else if (boundary.pendingTasks > 0) {
boundary.rootSegmentID = request.nextSegmentId++;
if (boundary.completedSegments.length > 0) {
request.partialBoundaries.push(boundary);
}
var id = boundary.id = assignSuspenseBoundaryID(request.responseState);
writeStartPendingSuspenseBoundary(destination, request.responseState, id);
flushSubtree(request, destination, segment);
return writeEndPendingSuspenseBoundary(destination, request.responseState);
} else if (boundary.byteSize > request.progressiveChunkSize) {
boundary.rootSegmentID = request.nextSegmentId++;
request.completedBoundaries.push(boundary);
writeStartPendingSuspenseBoundary(destination, request.responseState, boundary.id);
flushSubtree(request, destination, segment);
return writeEndPendingSuspenseBoundary(destination, request.responseState);
} else {
writeStartCompletedSuspenseBoundary(destination, request.responseState);
var completedSegments = boundary.completedSegments;
if (completedSegments.length !== 1) {
throw new Error("A previously unvisited boundary must have exactly one root segment. This is a bug in React.");
}
var contentSegment = completedSegments[0];
flushSegment(request, destination, contentSegment);
return writeEndCompletedSuspenseBoundary(destination, request.responseState);
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushSegment
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushClientRenderedBoundary(request, destination, boundary) {
return writeClientRenderBoundaryInstruction(destination, request.responseState, boundary.id, boundary.errorDigest, boundary.errorMessage, boundary.errorComponentStack);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushClientRenderedBoundary
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushSegmentContainer(request, destination, segment) {
writeStartSegment(destination, request.responseState, segment.formatContext, segment.id);
flushSegment(request, destination, segment);
return writeEndSegment(destination, segment.formatContext);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushSegmentContainer
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushCompletedBoundary(request, destination, boundary) {
var completedSegments = boundary.completedSegments;
var i = 0;
for (; i < completedSegments.length; i++) {
var segment = completedSegments[i];
flushPartiallyCompletedSegment(request, destination, boundary, segment);
}
completedSegments.length = 0;
return writeCompletedBoundaryInstruction(destination, request.responseState, boundary.id, boundary.rootSegmentID);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushCompletedBoundary
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushPartialBoundary(request, destination, boundary) {
var completedSegments = boundary.completedSegments;
var i = 0;
for (; i < completedSegments.length; i++) {
var segment = completedSegments[i];
if (!flushPartiallyCompletedSegment(request, destination, boundary, segment)) {
i++;
completedSegments.splice(0, i);
return false;
}
}
completedSegments.splice(0, i);
return true;
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushPartialBoundary
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushPartiallyCompletedSegment(request, destination, boundary, segment) {
if (segment.status === FLUSHED) {
return true;
}
var segmentID = segment.id;
if (segmentID === -1) {
var rootSegmentID = segment.id = boundary.rootSegmentID;
if (rootSegmentID === -1) {
throw new Error("A root segment ID must have been assigned by now. This is a bug in React.");
}
return flushSegmentContainer(request, destination, segment);
} else {
flushSegmentContainer(request, destination, segment);
return writeCompletedSegmentInstruction(destination, request.responseState, segmentID);
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushPartiallyCompletedSegment
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function flushCompletedQueues(request, destination) {
beginWriting();
try {
var completedRootSegment = request.completedRootSegment;
if (completedRootSegment !== null && request.pendingRootTasks === 0) {
flushSegment(request, destination, completedRootSegment);
request.completedRootSegment = null;
writeCompletedRoot(destination, request.responseState);
}
var clientRenderedBoundaries = request.clientRenderedBoundaries;
var i;
for (i = 0; i < clientRenderedBoundaries.length; i++) {
var boundary = clientRenderedBoundaries[i];
if (!flushClientRenderedBoundary(request, destination, boundary)) {
request.destination = null;
i++;
clientRenderedBoundaries.splice(0, i);
return;
}
}
clientRenderedBoundaries.splice(0, i);
var completedBoundaries = request.completedBoundaries;
for (i = 0; i < completedBoundaries.length; i++) {
var _boundary = completedBoundaries[i];
if (!flushCompletedBoundary(request, destination, _boundary)) {
request.destination = null;
i++;
completedBoundaries.splice(0, i);
return;
}
}
completedBoundaries.splice(0, i);
completeWriting(destination);
beginWriting(destination);
var partialBoundaries = request.partialBoundaries;
for (i = 0; i < partialBoundaries.length; i++) {
var _boundary2 = partialBoundaries[i];
if (!flushPartialBoundary(request, destination, _boundary2)) {
request.destination = null;
i++;
partialBoundaries.splice(0, i);
return;
}
}
partialBoundaries.splice(0, i);
var largeBoundaries = request.completedBoundaries;
for (i = 0; i < largeBoundaries.length; i++) {
var _boundary3 = largeBoundaries[i];
if (!flushCompletedBoundary(request, destination, _boundary3)) {
request.destination = null;
i++;
largeBoundaries.splice(0, i);
return;
}
}
largeBoundaries.splice(0, i);
} finally {
completeWriting(destination);
if (request.allPendingTasks === 0 && request.pingedTasks.length === 0 && request.clientRenderedBoundaries.length === 0 && request.completedBoundaries.length === 0) {
{
if (request.abortableTasks.size !== 0) {
error("There was still abortable task at the root when we closed. This is a bug in React.");
}
}
close(destination);
}
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
flushCompletedQueues
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function startWork(request) {
scheduleWork(function() {
return performWork(request);
});
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
startWork
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function startFlowing(request, destination) {
if (request.status === CLOSING) {
request.status = CLOSED;
closeWithError(destination, request.fatalError);
return;
}
if (request.status === CLOSED) {
return;
}
if (request.destination !== null) {
return;
}
request.destination = destination;
try {
flushCompletedQueues(request, destination);
} catch (error2) {
logRecoverableError(request, error2);
fatalError(request, error2);
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
startFlowing
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function abort(request, reason) {
try {
var abortableTasks = request.abortableTasks;
abortableTasks.forEach(function(task) {
return abortTask(task, request, reason);
});
abortableTasks.clear();
if (request.destination !== null) {
flushCompletedQueues(request, request.destination);
}
} catch (error2) {
logRecoverableError(request, error2);
fatalError(request, error2);
}
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
abort
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function renderToReadableStream(children, options) {
return new Promise(function(resolve, reject) {
var onFatalError;
var onAllReady;
var allReady = new Promise(function(res, rej) {
onAllReady = res;
onFatalError = rej;
});
function onShellReady() {
var stream = new ReadableStream(
{
type: "bytes",
pull: function(controller) {
startFlowing(request, controller);
},
cancel: function(reason) {
abort(request);
}
},
// $FlowFixMe size() methods are not allowed on byte streams.
{
highWaterMark: 0
}
);
stream.allReady = allReady;
resolve(stream);
}
function onShellError(error2) {
allReady.catch(function() {
});
reject(error2);
}
var request = createRequest(children, createResponseState(options ? options.identifierPrefix : void 0, options ? options.nonce : void 0, options ? options.bootstrapScriptContent : void 0, options ? options.bootstrapScripts : void 0, options ? options.bootstrapModules : void 0), createRootFormatContext(options ? options.namespaceURI : void 0), options ? options.progressiveChunkSize : void 0, options ? options.onError : void 0, onAllReady, onShellReady, onShellError, onFatalError);
if (options && options.signal) {
var signal = options.signal;
var listener = function() {
abort(request, signal.reason);
signal.removeEventListener("abort", listener);
};
signal.addEventListener("abort", listener);
}
startWork(request);
});
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
renderToReadableStream
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function onShellReady() {
var stream = new ReadableStream(
{
type: "bytes",
pull: function(controller) {
startFlowing(request, controller);
},
cancel: function(reason) {
abort(request);
}
},
// $FlowFixMe size() methods are not allowed on byte streams.
{
highWaterMark: 0
}
);
stream.allReady = allReady;
resolve(stream);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
onShellReady
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function onShellError(error2) {
allReady.catch(function() {
});
reject(error2);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
onShellError
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
listener = function() {
abort(request, signal.reason);
signal.removeEventListener("abort", listener);
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
listener
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
constructHTML = (app) => {
return `
<!doctype html>
<html>
<body>
<div id="content">${app}</div>
</body>
</html>
`;
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
constructHTML
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
handleRequest = async (request) => {
const headers = { "Content-Type": "text/html; charset=utf-8" };
const app = import_server.default.renderToString(/* @__PURE__ */ import_react2.default.createElement(app_default, null));
const html = constructHTML(app);
return new Response(html, { status: 200, headers });
}
|
Sets a subset of the state. This only exists because _pendingState is
internal. This provides a merging strategy that is not available to deep
properties which is confusing. TODO: Expose pendingState or don't use it
during the merge.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialState Next partial state to be merged with state.
@param {?function} callback Called after component is updated.
@param {?string} Name of the calling function in the public API.
@internal
|
handleRequest
|
javascript
|
wasmerio/winterjs
|
benchmark/complex.js
|
https://github.com/wasmerio/winterjs/blob/master/benchmark/complex.js
|
MIT
|
function Buffer(arg, encodingOrOffset, length) {
// Common case.
if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') {
throw new TypeError(
'The "string" argument must be of type string. Received type number'
)
}
return allocUnsafe(arg)
}
return from(arg, encodingOrOffset, length)
}
|
The Buffer constructor returns instances of `Uint8Array` that have their
prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
`Uint8Array`, so the returned instances will have all the node `Buffer` methods
and the `Uint8Array` methods. Square bracket notation works as expected -- it
returns a single octet.
The `Uint8Array` prototype remains unmodified.
|
Buffer
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function from(value, encodingOrOffset, length) {
if (typeof value === 'string') {
return fromString(value, encodingOrOffset)
}
if (ArrayBuffer.isView(value)) {
return fromArrayView(value)
}
if (value == null) {
throw new TypeError(
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
'or Array-like Object. Received type ' + (typeof value)
)
}
if (isInstance(value, ArrayBuffer) ||
(value && isInstance(value.buffer, ArrayBuffer))) {
return fromArrayBuffer(value, encodingOrOffset, length)
}
if (typeof SharedArrayBuffer !== 'undefined' &&
(isInstance(value, SharedArrayBuffer) ||
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
return fromArrayBuffer(value, encodingOrOffset, length)
}
if (typeof value === 'number') {
throw new TypeError(
'The "value" argument must not be of type number. Received type number'
)
}
const valueOf = value.valueOf && value.valueOf()
if (valueOf != null && valueOf !== value) {
return Buffer.from(valueOf, encodingOrOffset, length)
}
const b = fromObject(value)
if (b) return b
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
typeof value[Symbol.toPrimitive] === 'function') {
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
}
throw new TypeError(
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
'or Array-like Object. Received type ' + (typeof value)
)
}
|
The Buffer constructor returns instances of `Uint8Array` that have their
prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
`Uint8Array`, so the returned instances will have all the node `Buffer` methods
and the `Uint8Array` methods. Square bracket notation works as expected -- it
returns a single octet.
The `Uint8Array` prototype remains unmodified.
|
from
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function assertSize(size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be of type number')
} else if (size < 0) {
throw new RangeError('The value "' + size + '" is invalid for option "size"')
}
}
|
Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
if value is a number.
Buffer.from(str[, encoding])
Buffer.from(array)
Buffer.from(buffer)
Buffer.from(arrayBuffer[, byteOffset[, length]])
|
assertSize
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function alloc(size, fill, encoding) {
assertSize(size)
if (size <= 0) {
return createBuffer(size)
}
if (fill !== undefined) {
// Only pay attention to encoding if it's a string. This
// prevents accidentally sending in a number that would
// be interpreted as a start offset.
return typeof encoding === 'string'
? createBuffer(size).fill(fill, encoding)
: createBuffer(size).fill(fill)
}
return createBuffer(size)
}
|
Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
if value is a number.
Buffer.from(str[, encoding])
Buffer.from(array)
Buffer.from(buffer)
Buffer.from(arrayBuffer[, byteOffset[, length]])
|
alloc
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function allocUnsafe(size) {
assertSize(size)
return createBuffer(size < 0 ? 0 : checked(size) | 0)
}
|
Creates a new filled Buffer instance.
alloc(size[, fill[, encoding]])
|
allocUnsafe
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function fromString(string, encoding) {
if (typeof encoding !== 'string' || encoding === '') {
encoding = 'utf8'
}
if (!Buffer.isEncoding(encoding)) {
throw new TypeError('Unknown encoding: ' + encoding)
}
const length = byteLength(string, encoding) | 0
let buf = createBuffer(length)
const actual = buf.write(string, encoding)
if (actual !== length) {
// Writing a hex string, for example, that contains invalid characters will
// cause everything after the first invalid character to be ignored. (e.g.
// 'abxxcd' will be treated as 'ab')
buf = buf.slice(0, actual)
}
return buf
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
fromString
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function fromArrayLike(array) {
const length = array.length < 0 ? 0 : checked(array.length) | 0
const buf = createBuffer(length)
for (let i = 0; i < length; i += 1) {
buf[i] = array[i] & 255
}
return buf
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
fromArrayLike
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function fromArrayView(arrayView) {
if (isInstance(arrayView, Uint8Array)) {
const copy = new Uint8Array(arrayView)
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
}
return fromArrayLike(arrayView)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
fromArrayView
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function fromArrayBuffer(array, byteOffset, length) {
if (byteOffset < 0 || array.byteLength < byteOffset) {
throw new RangeError('"offset" is outside of buffer bounds')
}
if (array.byteLength < byteOffset + (length || 0)) {
throw new RangeError('"length" is outside of buffer bounds')
}
let buf
if (byteOffset === undefined && length === undefined) {
buf = new Uint8Array(array)
} else if (length === undefined) {
buf = new Uint8Array(array, byteOffset)
} else {
buf = new Uint8Array(array, byteOffset, length)
}
// Return an augmented `Uint8Array` instance
Object.setPrototypeOf(buf, Buffer.prototype)
return buf
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
fromArrayBuffer
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function fromObject(obj) {
if (Buffer.isBuffer(obj)) {
const len = checked(obj.length) | 0
const buf = createBuffer(len)
if (buf.length === 0) {
return buf
}
obj.copy(buf, 0, 0, len)
return buf
}
if (obj.length !== undefined) {
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
return createBuffer(0)
}
return fromArrayLike(obj)
}
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
return fromArrayLike(obj.data)
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
fromObject
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function checked(length) {
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
// length is NaN (which is otherwise coerced to zero.)
if (length >= K_MAX_LENGTH) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
}
return length | 0
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
checked
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function SlowBuffer(length) {
if (+length != length) { // eslint-disable-line eqeqeq
length = 0
}
return Buffer.alloc(+length)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
SlowBuffer
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function byteLength(string, encoding) {
if (Buffer.isBuffer(string)) {
return string.length
}
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
return string.byteLength
}
if (typeof string !== 'string') {
throw new TypeError(
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
'Received type ' + typeof string
)
}
const len = string.length
const mustMatch = (arguments.length > 2 && arguments[2] === true)
if (!mustMatch && len === 0) return 0
// Use a for loop to avoid recursion
let loweredCase = false
for (; ;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
return len
case 'utf8':
case 'utf-8':
return utf8ToBytes(string).length
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return len * 2
case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) {
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
}
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
byteLength
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function slowToString(encoding, start, end) {
let loweredCase = false
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
// property of a typed array.
// This behaves neither like String nor Uint8Array in that we set start/end
// to their upper/lower bounds if the value passed is out of range.
// undefined is handled specially as per ECMA-262 6th Edition,
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
if (start === undefined || start < 0) {
start = 0
}
// Return early if start > this.length. Done here to prevent potential uint32
// coercion fail below.
if (start > this.length) {
return ''
}
if (end === undefined || end > this.length) {
end = this.length
}
if (end <= 0) {
return ''
}
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
end >>>= 0
start >>>= 0
if (end <= start) {
return ''
}
if (!encoding) encoding = 'utf8'
while (true) {
switch (encoding) {
case 'hex':
return hexSlice(this, start, end)
case 'utf8':
case 'utf-8':
return utf8Slice(this, start, end)
case 'ascii':
return asciiSlice(this, start, end)
case 'latin1':
case 'binary':
return latin1Slice(this, start, end)
case 'base64':
return base64Slice(this, start, end)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16leSlice(this, start, end)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase()
loweredCase = true
}
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
slowToString
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function swap(b, n, m) {
const i = b[n]
b[n] = b[m]
b[m] = i
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
swap
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
// Empty buffer means no match
if (buffer.length === 0) return -1
// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset
byteOffset = 0
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000
}
byteOffset = +byteOffset // Coerce to Number.
if (numberIsNaN(byteOffset)) {
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
byteOffset = dir ? 0 : (buffer.length - 1)
}
// Normalize byteOffset: negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
if (byteOffset >= buffer.length) {
if (dir) return -1
else byteOffset = buffer.length - 1
} else if (byteOffset < 0) {
if (dir) byteOffset = 0
else return -1
}
// Normalize val
if (typeof val === 'string') {
val = Buffer.from(val, encoding)
}
// Finally, search either indexOf (if dir is true) or lastIndexOf
if (Buffer.isBuffer(val)) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
} else if (typeof val === 'number') {
val = val & 0xFF // Search for a byte value [0-255]
if (typeof Uint8Array.prototype.indexOf === 'function') {
if (dir) {
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
} else {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
}
throw new TypeError('val must be string, number or Buffer')
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
bidirectionalIndexOf
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
let indexSize = 1
let arrLength = arr.length
let valLength = val.length
if (encoding !== undefined) {
encoding = String(encoding).toLowerCase()
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
encoding === 'utf16le' || encoding === 'utf-16le') {
if (arr.length < 2 || val.length < 2) {
return -1
}
indexSize = 2
arrLength /= 2
valLength /= 2
byteOffset /= 2
}
}
function read(buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
}
let i
if (dir) {
let foundIndex = -1
for (i = byteOffset; i < arrLength; i++) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex
foundIndex = -1
}
}
} else {
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
for (i = byteOffset; i >= 0; i--) {
let found = true
for (let j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {
found = false
break
}
}
if (found) return i
}
}
return -1
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
arrayIndexOf
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function read(buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
read
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function hexWrite(buf, string, offset, length) {
offset = Number(offset) || 0
const remaining = buf.length - offset
if (!length) {
length = remaining
} else {
length = Number(length)
if (length > remaining) {
length = remaining
}
}
const strLen = string.length
if (length > strLen / 2) {
length = strLen / 2
}
let i
for (i = 0; i < length; ++i) {
const a = hexCharValueTable[string[i * 2]]
const b = hexCharValueTable[string[i * 2 + 1]]
if (a === undefined || b === undefined) {
return i
}
buf[offset + i] = a << 4 | b
}
return i
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
hexWrite
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function utf8Write(buf, string, offset, length) {
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
utf8Write
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function asciiWrite(buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
asciiWrite
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function base64Write(buf, string, offset, length) {
return blitBuffer(base64ToBytes(string), buf, offset, length)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
base64Write
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function ucs2Write(buf, string, offset, length) {
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
ucs2Write
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function base64Slice(buf, start, end) {
if (start === 0 && end === buf.length) {
return base64.fromByteArray(buf)
} else {
return base64.fromByteArray(buf.slice(start, end))
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
base64Slice
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function utf8Slice(buf, start, end) {
end = Math.min(buf.length, end)
const res = []
let i = start
while (i < end) {
const firstByte = buf[i]
let codePoint = null
let bytesPerSequence = (firstByte > 0xEF)
? 4
: (firstByte > 0xDF)
? 3
: (firstByte > 0xBF)
? 2
: 1
if (i + bytesPerSequence <= end) {
let secondByte, thirdByte, fourthByte, tempCodePoint
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
codePoint = firstByte
}
break
case 2:
secondByte = buf[i + 1]
if ((secondByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
if (tempCodePoint > 0x7F) {
codePoint = tempCodePoint
}
}
break
case 3:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
codePoint = tempCodePoint
}
}
break
case 4:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
fourthByte = buf[i + 3]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
codePoint = tempCodePoint
}
}
}
}
if (codePoint === null) {
// we did not generate a valid codePoint so insert a
// replacement char (U+FFFD) and advance only 1 byte
codePoint = 0xFFFD
bytesPerSequence = 1
} else if (codePoint > 0xFFFF) {
// encode to utf16 (surrogate pair dance)
codePoint -= 0x10000
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
codePoint = 0xDC00 | codePoint & 0x3FF
}
res.push(codePoint)
i += bytesPerSequence
}
return decodeCodePointsArray(res)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
utf8Slice
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function decodeCodePointsArray(codePoints) {
const len = codePoints.length
if (len <= MAX_ARGUMENTS_LENGTH) {
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
}
// Decode in chunks to avoid "call stack size exceeded".
let res = ''
let i = 0
while (i < len) {
res += String.fromCharCode.apply(
String,
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
)
}
return res
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
decodeCodePointsArray
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function asciiSlice(buf, start, end) {
let ret = ''
end = Math.min(buf.length, end)
for (let i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i] & 0x7F)
}
return ret
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
asciiSlice
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function latin1Slice(buf, start, end) {
let ret = ''
end = Math.min(buf.length, end)
for (let i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i])
}
return ret
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
latin1Slice
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function hexSlice(buf, start, end) {
const len = buf.length
if (!start || start < 0) start = 0
if (!end || end < 0 || end > len) end = len
let out = ''
for (let i = start; i < end; ++i) {
out += hexSliceLookupTable[buf[i]]
}
return out
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
hexSlice
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function utf16leSlice(buf, start, end) {
const bytes = buf.slice(start, end)
let res = ''
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
for (let i = 0; i < bytes.length - 1; i += 2) {
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
}
return res
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
utf16leSlice
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function checkOffset(offset, ext, length) {
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
checkOffset
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function checkInt(buf, value, offset, ext, max, min) {
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
if (offset + ext > buf.length) throw new RangeError('Index out of range')
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
checkInt
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function wrtBigUInt64LE(buf, value, offset, min, max) {
checkIntBI(value, min, max, buf, offset, 7)
let lo = Number(value & BigInt(0xffffffff))
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
return offset
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
wrtBigUInt64LE
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function wrtBigUInt64BE(buf, value, offset, min, max) {
checkIntBI(value, min, max, buf, offset, 7)
let lo = Number(value & BigInt(0xffffffff))
buf[offset + 7] = lo
lo = lo >> 8
buf[offset + 6] = lo
lo = lo >> 8
buf[offset + 5] = lo
lo = lo >> 8
buf[offset + 4] = lo
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
buf[offset + 3] = hi
hi = hi >> 8
buf[offset + 2] = hi
hi = hi >> 8
buf[offset + 1] = hi
hi = hi >> 8
buf[offset] = hi
return offset + 8
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
wrtBigUInt64BE
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function checkIEEE754(buf, value, offset, ext, max, min) {
if (offset + ext > buf.length) throw new RangeError('Index out of range')
if (offset < 0) throw new RangeError('Index out of range')
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
checkIEEE754
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function writeFloat(buf, value, offset, littleEndian, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) {
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
}
ieee754.write(buf, value, offset, littleEndian, 23, 4)
return offset + 4
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
writeFloat
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function writeDouble(buf, value, offset, littleEndian, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) {
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
}
ieee754.write(buf, value, offset, littleEndian, 52, 8)
return offset + 8
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
writeDouble
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function E(sym, getMessage, Base) {
errors[sym] = class NodeError extends Base {
constructor() {
super()
Object.defineProperty(this, 'message', {
value: getMessage.apply(this, arguments),
writable: true,
configurable: true
})
// Add the error code to the name to include it in the stack trace.
this.name = `${this.name} [${sym}]`
// Access the stack to generate the error message including the error code
// from the name.
this.stack // eslint-disable-line no-unused-expressions
// Reset the name to the actual name.
delete this.name
}
get code() {
return sym
}
set code(value) {
Object.defineProperty(this, 'code', {
configurable: true,
enumerable: true,
value,
writable: true
})
}
toString() {
return `${this.name} [${sym}]: ${this.message}`
}
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
E
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
constructor() {
super()
Object.defineProperty(this, 'message', {
value: getMessage.apply(this, arguments),
writable: true,
configurable: true
})
// Add the error code to the name to include it in the stack trace.
this.name = `${this.name} [${sym}]`
// Access the stack to generate the error message including the error code
// from the name.
this.stack // eslint-disable-line no-unused-expressions
// Reset the name to the actual name.
delete this.name
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
constructor
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
get code() {
return sym
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
code
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
set code(value) {
Object.defineProperty(this, 'code', {
configurable: true,
enumerable: true,
value,
writable: true
})
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
code
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
toString() {
return `${this.name} [${sym}]: ${this.message}`
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
toString
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function addNumericalSeparator(val) {
let res = ''
let i = val.length
const start = val[0] === '-' ? 1 : 0
for (; i >= start + 4; i -= 3) {
res = `_${val.slice(i - 3, i)}${res}`
}
return `${val.slice(0, i)}${res}`
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
addNumericalSeparator
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function checkBounds(buf, offset, byteLength) {
validateNumber(offset, 'offset')
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
boundsError(offset, buf.length - (byteLength + 1))
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
checkBounds
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function checkIntBI(value, min, max, buf, offset, byteLength) {
if (value > max || value < min) {
const n = typeof min === 'bigint' ? 'n' : ''
let range
if (byteLength > 3) {
if (min === 0 || min === BigInt(0)) {
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`
} else {
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
`${(byteLength + 1) * 8 - 1}${n}`
}
} else {
range = `>= ${min}${n} and <= ${max}${n}`
}
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
}
checkBounds(buf, offset, byteLength)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
checkIntBI
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function validateNumber(value, name) {
if (typeof value !== 'number') {
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
validateNumber
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function boundsError(value, length, type) {
if (Math.floor(value) !== value) {
validateNumber(value, type)
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
}
if (length < 0) {
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
}
throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
`>= ${type ? 1 : 0} and <= ${length}`,
value)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
boundsError
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function base64clean(str) {
// Node takes equal signs as end of the Base64 encoding
str = str.split('=')[0]
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = str.trim().replace(INVALID_BASE64_RE, '')
// Node converts strings with length < 2 to ''
if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '='
}
return str
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
base64clean
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function utf8ToBytes(string, units) {
units = units || Infinity
let codePoint
const length = string.length
let leadSurrogate = null
const bytes = []
for (let i = 0; i < length; ++i) {
codePoint = string.charCodeAt(i)
// is surrogate component
if (codePoint > 0xD7FF && codePoint < 0xE000) {
// last char was a lead
if (!leadSurrogate) {
// no lead yet
if (codePoint > 0xDBFF) {
// unexpected trail
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
} else if (i + 1 === length) {
// unpaired lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
}
// valid lead
leadSurrogate = codePoint
continue
}
// 2 leads in a row
if (codePoint < 0xDC00) {
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
leadSurrogate = codePoint
continue
}
// valid surrogate pair
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
} else if (leadSurrogate) {
// valid bmp char, but last char was a lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
}
leadSurrogate = null
// encode utf8
if (codePoint < 0x80) {
if ((units -= 1) < 0) break
bytes.push(codePoint)
} else if (codePoint < 0x800) {
if ((units -= 2) < 0) break
bytes.push(
codePoint >> 0x6 | 0xC0,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x10000) {
if ((units -= 3) < 0) break
bytes.push(
codePoint >> 0xC | 0xE0,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x110000) {
if ((units -= 4) < 0) break
bytes.push(
codePoint >> 0x12 | 0xF0,
codePoint >> 0xC & 0x3F | 0x80,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else {
throw new Error('Invalid code point')
}
}
return bytes
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
utf8ToBytes
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function asciiToBytes(str) {
const byteArray = []
for (let i = 0; i < str.length; ++i) {
// Node's code seems to be doing this and not & 0x7F..
byteArray.push(str.charCodeAt(i) & 0xFF)
}
return byteArray
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
asciiToBytes
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function utf16leToBytes(str, units) {
let c, hi, lo
const byteArray = []
for (let i = 0; i < str.length; ++i) {
if ((units -= 2) < 0) break
c = str.charCodeAt(i)
hi = c >> 8
lo = c % 256
byteArray.push(lo)
byteArray.push(hi)
}
return byteArray
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
utf16leToBytes
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function base64ToBytes(str) {
return base64.toByteArray(base64clean(str))
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
base64ToBytes
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function blitBuffer(src, dst, offset, length) {
let i
for (i = 0; i < length; ++i) {
if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i]
}
return i
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
blitBuffer
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function isInstance(obj, type) {
return obj instanceof type ||
(obj != null && obj.constructor != null && obj.constructor.name != null &&
obj.constructor.name === type.name)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
isInstance
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function numberIsNaN(obj) {
// For IE11 support
return obj !== obj // eslint-disable-line no-self-compare
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
numberIsNaN
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function defineBigIntMethod(fn) {
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
defineBigIntMethod
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
function BufferBigIntNotDefined() {
throw new Error('BigInt not supported')
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
BufferBigIntNotDefined
|
javascript
|
wasmerio/winterjs
|
src/builtins/internal_js_modules/node/buffer.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/internal_js_modules/node/buffer.js
|
MIT
|
set returnValue(value) {
if (!value)
this.canceledFlag = true;
}
|
The returnValue setter steps are to set the canceled flag with this if the given value is false; otherwise do nothing.
|
returnValue
|
javascript
|
wasmerio/winterjs
|
src/builtins/js_globals/event.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/js_globals/event.js
|
MIT
|
preventDefault() {
this.canceledFlag = true;
}
|
The preventDefault() method steps are to set the canceled flag with this.
|
preventDefault
|
javascript
|
wasmerio/winterjs
|
src/builtins/js_globals/event.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/js_globals/event.js
|
MIT
|
get defaultPrevented() {
return !!this.canceledFlag;
}
|
The preventDefault() method steps are to set the canceled flag with this.
|
defaultPrevented
|
javascript
|
wasmerio/winterjs
|
src/builtins/js_globals/event.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/js_globals/event.js
|
MIT
|
get composed() {
return !!this.composedFlag;
}
|
The preventDefault() method steps are to set the canceled flag with this.
|
composed
|
javascript
|
wasmerio/winterjs
|
src/builtins/js_globals/event.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/js_globals/event.js
|
MIT
|
get dispatched() {
return this.dispatchFlag;
}
|
The preventDefault() method steps are to set the canceled flag with this.
|
dispatched
|
javascript
|
wasmerio/winterjs
|
src/builtins/js_globals/event.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/js_globals/event.js
|
MIT
|
set dispatched(value) {
this.dispatchFlag = value;
}
|
The preventDefault() method steps are to set the canceled flag with this.
|
dispatched
|
javascript
|
wasmerio/winterjs
|
src/builtins/js_globals/event.js
|
https://github.com/wasmerio/winterjs/blob/master/src/builtins/js_globals/event.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.