Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions lib/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ const builtIns = {

concat: new AbstractFunction(),
endsWith: new AbstractFunction(),
includes: new AbstractFunction(),
includes: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'includes' }, [{ name: 'searchElement' }, { name: 'fromIndex' }]),
indexOf: new AbstractFunction(),
lastIndexOf: new AbstractFunction(),
localeCompare: new AbstractFunction(),
match: new AbstractFunction(),
matchAll: new AbstractFunction(),
match: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'match' }, [{ name: 'pattern' }]),
matchAll: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'matchAll' }, [{ name: 'pattern' }]),
normalize: new AbstractFunction(),
padEnd: new AbstractFunction(),
padStart: new AbstractFunction(),
repeat: new AbstractFunction(),
replace: new AbstractFunction(),
replaceAll: new AbstractFunction(),
search: new AbstractFunction(),
replace: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'replace' }, [{ name: 'searchValue' }, { name: 'newValue' }]),
replaceAll: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'replaceAll' }, [{ name: 'searchValue' }, { name: 'newValue' }]),
search: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'search' }, [{ name: 'pattern' }]),
slice: new AbstractFunction(),
split: new AbstractFunction(),
startsWith: new AbstractFunction(),
Expand Down Expand Up @@ -318,6 +318,43 @@ const builtInsImpls = {
valueOf: (target, context, options, runState) => {
return target.valueOf();
},
includes: (target, context, options, runState) => {
const elem = context.get('searchElement');
const from = context.get('fromIndex');
return target.includes(elem, from);
},
match: (target, context, options, runState) => {
const pattern = context.get('pattern');
return target.match(pattern);
},
matchAll: (target, context, options, runState) => {
const pattern = context.get('pattern');
return target.matchAll(pattern);
},
replace: (target, context, options, runState) => {
const searchValue = context.get('searchValue');
const newValue = context.get('newValue');
return target.replace(
searchValue,
newValue instanceof AbstractFunction ?
(x) => newValue.exec([x], context, options, runState) :
newValue
)
},
replaceAll: (target, context, options, runState) => {
const searchValue = context.get('searchValue');
const newValue = context.get('newValue');
return target.replaceAll(
searchValue,
newValue instanceof AbstractFunction ?
(x) => newValue.exec([x], context, options, runState) :
newValue
);
},
search: (target, context, options, runState) => {
const pattern = context.get('pattern');
return target.search(pattern);
},
},
JSON: {
parse: (target, context, options, runState) => {
Expand Down