function Promise.Resolve(c,...)if not c._pendingExecuteList then return end local O=select("\035",...)if O==0 then c:_fulfill({},0)elseif c==...then c: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 O>1 then local O=("\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(c._source)warn(O)end local v=...if v._pendingExecuteList then v._unconsumedException=false v._pendingExecuteList[#v._pendingExecuteList+1]={function(...)c:Resolve(...)end;function(...)if c._pendingExecuteList then c:_reject({...},select("\035",...))end end;nil}elseif v._rejected then v._unconsumedException=false c:_reject(v._rejected,v._valuesLength)elseif v._fulfilled then c:_fulfill(v._fulfilled,v._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 O>1 then local O=("\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(c._source)warn(O)end local v={...}v(c:_getResolveReject())else c:_fulfill({...},O)end end

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
