function Promise.Resolve(J,...)if not J._pendingExecuteList then return end local s=select("\035",...)if s==0 then J:_fulfill({},0)elseif J==...then J:Reject("\084\121\112\101\069\114\114\111\114\058 \082\101\115\111\108\118\101\100 \116\111 \115\101\108\102")elseif Promise.isPromise(...)then if s>1 then local s=("\087\104\101\110 \114\101\115\111\108\118\105\110\103 \097 \112\114\111\109\105\115\101\044 \101\120\116\114\097 \097\114\103\117\109\101\110\116\115 \097\114\101 \100\105\115\099\097\114\100\101\100\033 \083\101\101\058\n\n\037\115"):format(J._source)warn(s)end local q=...if q._pendingExecuteList then q._unconsumedException=false q._pendingExecuteList[#q._pendingExecuteList+1]={function(...)J:Resolve(...)end;function(...)if J._pendingExecuteList then J:_reject({...},select("\035",...))end end,nil}elseif q._rejected then q._unconsumedException=false J:_reject(q._rejected,q._valuesLength)elseif q._fulfilled then J:_fulfill(q._fulfilled,q._valuesLength)else error("\091\080\114\111\109\105\115\101\046\082\101\115\111\108\118\101\093 - \066\097\100 \112\114\111\109\105\115\101\050 \115\116\097\116\101")end elseif type(...)=="\102\117\110\099\116\105\111\110"then if s>1 then local s=("\087\104\101\110 \114\101\115\111\108\118\105\110\103 \097 \102\117\110\099\116\105\111\110\044 \101\120\116\114\097 \097\114\103\117\109\101\110\116\115 \097\114\101 \100\105\115\099\097\114\100\101\100\033 \083\101\101\058\n\n\037\115"):format(J._source)warn(s)end local q=...q(J:_getResolveReject())else J:_fulfill({...},s)end end
--[=[
	Promise resolution procedure, resolves the given values

	@param ... T
]=]
function Promise:Resolve(...)
	if not self._pendingExecuteList then
		return
	end

	local len = select("#", ...)
	if len == 0 then
		self:_fulfill({}, 0)
	elseif self == (...) then
		self:Reject("TypeError: Resolved to self")
	elseif Promise.isPromise(...) then
		if len > 1 then
			local message = ("When resolving a promise, extra arguments are discarded! See:\n\n%s"):format(self._source)
			warn(message)
		end

		local promise2 = (...)
		if promise2._pendingExecuteList then -- pending
			promise2._unconsumedException = false
			promise2._pendingExecuteList[#promise2._pendingExecuteList + 1] = {
				function(...)
					self:Resolve(...)
				end,
				function(...)
					-- Still need to verify at this point that we're pending!
					if self._pendingExecuteList then
						self:_reject({ ... }, select("#", ...))
					end
				end,
				nil,
			}
		elseif promise2._rejected then -- rejected
			promise2._unconsumedException = false
			self:_reject(promise2._rejected, promise2._valuesLength)
		elseif promise2._fulfilled then -- fulfilled
			self:_fulfill(promise2._fulfilled, promise2._valuesLength)
		else
			error("[Promise.Resolve] - Bad promise2 state")
		end
	elseif type(...) == "function" then
		if len > 1 then
			local message = ("When resolving a function, extra arguments are discarded! See:\n\n%s"):format(
				self._source
			)
			warn(message)
		end

		local func = ...
		func(self:_getResolveReject())
	else
		-- TODO: Handle thenable promises!
		-- Problem: Lua has :andThen() and also :Then() as two methods in promise
		-- implementations.
		self:_fulfill({ ... }, len)
	end
end
