// FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc. const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec) { if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) { initializingLazyNumericCompareFunction = true; RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(Identifier(exec, "numericCompare"), exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0); lazyNumericCompareFunction = function->bytecode(exec, exec->scopeChain()).instructions(); initializingLazyNumericCompareFunction = false; } return lazyNumericCompareFunction; }
Completion JSRun::Evaluate() { return JSC::evaluate(fGlobalObject->globalExec(), fGlobalObject->globalScopeChain(), makeSource(fSource)); }
bool JSRun::CheckSyntax() { return JSC::checkSyntax(fGlobalObject->globalExec(), makeSource(fSource)).complType() != Throw; }
JSObject* constructFunctionSkippingEvalEnabledCheck( ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, const Identifier& functionName, const String& sourceURL, const TextPosition& position, int overrideLineNumber, FunctionConstructionMode functionConstructionMode, JSValue newTarget) { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); const char* prefix = nullptr; Structure* structure = nullptr; switch (functionConstructionMode) { case FunctionConstructionMode::Function: structure = globalObject->functionStructure(); prefix = "{function "; break; case FunctionConstructionMode::Generator: structure = globalObject->generatorFunctionStructure(); prefix = "{function *"; break; case FunctionConstructionMode::Async: structure = globalObject->asyncFunctionStructure(); prefix = "{async function "; break; } // How we stringify functions is sometimes important for web compatibility. // See https://bugs.webkit.org/show_bug.cgi?id=24350. String program; if (args.isEmpty()) program = makeString(prefix, functionName.string(), "() {\n\n}}"); else if (args.size() == 1) program = makeString(prefix, functionName.string(), "() {\n", args.at(0).toString(exec)->value(exec), "\n}}"); else { StringBuilder builder; builder.append(prefix); builder.append(functionName.string()); builder.append('('); auto viewWithString = args.at(0).toString(exec)->viewWithUnderlyingString(*exec); RETURN_IF_EXCEPTION(scope, nullptr); builder.append(viewWithString.view); for (size_t i = 1; i < args.size() - 1; i++) { builder.appendLiteral(", "); auto viewWithString = args.at(i).toString(exec)->viewWithUnderlyingString(*exec); RETURN_IF_EXCEPTION(scope, nullptr); builder.append(viewWithString.view); } builder.appendLiteral(") {\n"); viewWithString = args.at(args.size() - 1).toString(exec)->viewWithUnderlyingString(*exec); RETURN_IF_EXCEPTION(scope, nullptr); builder.append(viewWithString.view); builder.appendLiteral("\n}}"); program = builder.toString(); } SourceCode source = makeSource(program, sourceURL, position); JSObject* exception = nullptr; FunctionExecutable* function = FunctionExecutable::fromGlobalCode(functionName, *exec, source, exception, overrideLineNumber); if (!function) { ASSERT(exception); return throwException(exec, scope, exception); } Structure* subclassStructure = InternalFunction::createSubclassStructure(exec, newTarget, structure); RETURN_IF_EXCEPTION(scope, nullptr); switch (functionConstructionMode) { case FunctionConstructionMode::Function: return JSFunction::create(vm, function, globalObject->globalScope(), subclassStructure); case FunctionConstructionMode::Generator: return JSGeneratorFunction::create(vm, function, globalObject->globalScope(), subclassStructure); case FunctionConstructionMode::Async: return JSAsyncFunction::create(vm, function, globalObject->globalScope(), subclassStructure); } ASSERT_NOT_REACHED(); return nullptr; }