[jsinterp] Fixing incomplete refactor
This commit is contained in:
parent
b8a1742d73
commit
848aa79a02
@ -16,7 +16,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||||||
from youtube_dl.jsinterp2 import JSInterpreter
|
from youtube_dl.jsinterp2 import JSInterpreter
|
||||||
from .jstests import gettestcases
|
from .jstests import gettestcases
|
||||||
|
|
||||||
__doc__ = """see: `js2tests`"""
|
__doc__ = """see: `jstests`"""
|
||||||
|
|
||||||
|
|
||||||
defs = gettestcases()
|
defs = gettestcases()
|
||||||
@ -71,12 +71,12 @@ def generator(test_case, my_log):
|
|||||||
return test_template
|
return test_template
|
||||||
|
|
||||||
|
|
||||||
# And add them to TestJSInterpreter2
|
# And add them to TestJSTestsJSInterpreter2
|
||||||
for testcase in defs:
|
for testcase in defs:
|
||||||
reason = testcase['skip'].get('interpret', False)
|
reason = testcase['skip'].get('interpret', False)
|
||||||
tname = 'test_' + str(testcase['name'])
|
tname = 'test_' + str(testcase['name'])
|
||||||
i = 1
|
i = 1
|
||||||
while hasattr(TestJSInterpreter2, tname):
|
while hasattr(TestJSTestsJSInterpreter2, tname):
|
||||||
tname = 'test_%s_%d' % (testcase['name'], i)
|
tname = 'test_%s_%d' % (testcase['name'], i)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ for testcase in defs:
|
|||||||
if reason is not False:
|
if reason is not False:
|
||||||
test_method.__unittest_skip__ = True
|
test_method.__unittest_skip__ = True
|
||||||
test_method.__unittest_skip_why__ = reason
|
test_method.__unittest_skip_why__ = reason
|
||||||
setattr(TestJSInterpreter2, test_method.__name__, test_method)
|
setattr(TestJSTestsJSInterpreter2, test_method.__name__, test_method)
|
||||||
del test_method
|
del test_method
|
||||||
else:
|
else:
|
||||||
log.info('Skipping %s:%s' % (tname, log_reason))
|
log.info('Skipping %s:%s' % (tname, log_reason))
|
||||||
|
@ -17,7 +17,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||||||
from youtube_dl.jsinterp2.jsparser import Parser
|
from youtube_dl.jsinterp2.jsparser import Parser
|
||||||
from .jstests import gettestcases
|
from .jstests import gettestcases
|
||||||
|
|
||||||
__doc__ = """see: `js2tests`"""
|
__doc__ = """see: `jstests`"""
|
||||||
|
|
||||||
|
|
||||||
def traverse(node, tree_types=(list, tuple)):
|
def traverse(node, tree_types=(list, tuple)):
|
||||||
@ -64,12 +64,12 @@ def generator(test_case, my_log):
|
|||||||
return test_template
|
return test_template
|
||||||
|
|
||||||
|
|
||||||
# And add them to TestJSInterpreter2Parse
|
# And add them to TestJSTestsJSInterpreter2Parse
|
||||||
for testcase in defs:
|
for testcase in defs:
|
||||||
reason = testcase['skip'].get('parse', False)
|
reason = testcase['skip'].get('parse', False)
|
||||||
tname = 'test_' + str(testcase['name'])
|
tname = 'test_' + str(testcase['name'])
|
||||||
i = 1
|
i = 1
|
||||||
while hasattr(TestJSInterpreter2Parse, tname):
|
while hasattr(TestJSTestsJSInterpreter2Parse, tname):
|
||||||
tname = 'test_%s_%d' % (testcase['name'], i)
|
tname = 'test_%s_%d' % (testcase['name'], i)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ for testcase in defs:
|
|||||||
if reason is not False:
|
if reason is not False:
|
||||||
test_method.__unittest_skip__ = True
|
test_method.__unittest_skip__ = True
|
||||||
test_method.__unittest_skip_why__ = reason
|
test_method.__unittest_skip_why__ = reason
|
||||||
setattr(TestJSInterpreter2Parse, test_method.__name__, test_method)
|
setattr(TestJSTestsJSInterpreter2Parse, test_method.__name__, test_method)
|
||||||
del test_method
|
del test_method
|
||||||
else:
|
else:
|
||||||
log.info('Skipping %s:%s' % (tname, log_reason))
|
log.info('Skipping %s:%s' % (tname, log_reason))
|
||||||
|
@ -16,7 +16,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||||||
from youtube_dl.jsinterp import JSInterpreter
|
from youtube_dl.jsinterp import JSInterpreter
|
||||||
from .jstests import gettestcases
|
from .jstests import gettestcases
|
||||||
|
|
||||||
__doc__ = """see: `js2tests`"""
|
__doc__ = """see: `jstests`"""
|
||||||
|
|
||||||
|
|
||||||
defs = gettestcases()
|
defs = gettestcases()
|
||||||
@ -74,12 +74,12 @@ def generator(test_case, my_log):
|
|||||||
return test_template
|
return test_template
|
||||||
|
|
||||||
|
|
||||||
# And add them to TestJSInterpreter
|
# And add them to TestJSTestsJSInterpreter
|
||||||
for testcase in defs:
|
for testcase in defs:
|
||||||
reason = testcase['skip'].get('jsinterp', False)
|
reason = testcase['skip'].get('jsinterp', False)
|
||||||
tname = 'test_' + str(testcase['name'])
|
tname = 'test_' + str(testcase['name'])
|
||||||
i = 1
|
i = 1
|
||||||
while hasattr(TestJSInterpreter, tname):
|
while hasattr(TestJSTestsJSInterpreter, tname):
|
||||||
tname = 'test_%s_%d' % (testcase['name'], i)
|
tname = 'test_%s_%d' % (testcase['name'], i)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ for testcase in defs:
|
|||||||
if reason is not False:
|
if reason is not False:
|
||||||
test_method.__unittest_skip__ = True
|
test_method.__unittest_skip__ = True
|
||||||
test_method.__unittest_skip_why__ = reason
|
test_method.__unittest_skip_why__ = reason
|
||||||
setattr(TestJSInterpreter, test_method.__name__, test_method)
|
setattr(TestJSTestsJSInterpreter, test_method.__name__, test_method)
|
||||||
del test_method
|
del test_method
|
||||||
else:
|
else:
|
||||||
log.info('Skipping %s:%s' % (tname, log_reason))
|
log.info('Skipping %s:%s' % (tname, log_reason))
|
||||||
|
@ -12,7 +12,7 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from .common import InfoExtractor, SearchInfoExtractor
|
from .common import InfoExtractor, SearchInfoExtractor
|
||||||
from ..jsinterp import JSInterpreter
|
from ..jsinterp2 import JSInterpreter
|
||||||
from ..swfinterp import SWFInterpreter
|
from ..swfinterp import SWFInterpreter
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_chr,
|
compat_chr,
|
||||||
@ -1165,7 +1165,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
|
|
||||||
jsi = JSInterpreter(jscode)
|
jsi = JSInterpreter(jscode)
|
||||||
initial_function = jsi.extract_function(funcname)
|
initial_function = jsi.extract_function(funcname)
|
||||||
return lambda s: initial_function([s])
|
return lambda s: initial_function(*s)
|
||||||
|
|
||||||
def _parse_sig_swf(self, file_contents):
|
def _parse_sig_swf(self, file_contents):
|
||||||
swfi = SWFInterpreter(file_contents)
|
swfi = SWFInterpreter(file_contents)
|
||||||
|
@ -66,6 +66,7 @@ def to_number(o):
|
|||||||
from .jsobject import JSObjectPrototype
|
from .jsobject import JSObjectPrototype
|
||||||
from .jsboolean import JSBooleanPrototype, false, true
|
from .jsboolean import JSBooleanPrototype, false, true
|
||||||
from .jsstring import JSStringPrototype
|
from .jsstring import JSStringPrototype
|
||||||
|
from .jsnumber import JSNumberPrototype
|
||||||
|
|
||||||
if o is undefined:
|
if o is undefined:
|
||||||
return float('nan')
|
return float('nan')
|
||||||
@ -73,6 +74,8 @@ def to_number(o):
|
|||||||
return 0
|
return 0
|
||||||
elif isinstance(o, JSBooleanPrototype) and o.value is true:
|
elif isinstance(o, JSBooleanPrototype) and o.value is true:
|
||||||
return 1
|
return 1
|
||||||
|
elif isinstance(o, JSNumberPrototype):
|
||||||
|
return o.value
|
||||||
elif isinstance(o, JSStringPrototype):
|
elif isinstance(o, JSStringPrototype):
|
||||||
_STR_FLOAT_RE = r'(?:(?:[0-9]+(?:\.[0-9]*)?)|(?:\.[0-9]+))(?:[eE][+-]?[0-9]+)?'
|
_STR_FLOAT_RE = r'(?:(?:[0-9]+(?:\.[0-9]*)?)|(?:\.[0-9]+))(?:[eE][+-]?[0-9]+)?'
|
||||||
m = re.match(r'^[\s\n]*(?P<value>(?:[+-]*(?:Infinity|%(float)s))|%(hex)s)?[\s\n]*$' % {'float': _STR_FLOAT_RE,
|
m = re.match(r'^[\s\n]*(?P<value>(?:[+-]*(?:Infinity|%(float)s))|%(hex)s)?[\s\n]*$' % {'float': _STR_FLOAT_RE,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from youtube_dl.jsinterp2.jsbuilt_ins.internals import to_uint32, to_integer
|
||||||
from .base import native_number, undefined
|
from .base import native_number, undefined
|
||||||
from .jsobject import JSObject, JSObjectPrototype
|
from .jsobject import JSObject, JSObjectPrototype
|
||||||
from .jsnumber import JSNumberPrototype
|
from .jsnumber import JSNumberPrototype
|
||||||
@ -55,8 +56,15 @@ class JSArrayPrototype(JSObjectPrototype):
|
|||||||
def _shift(self):
|
def _shift(self):
|
||||||
return 'array shift'
|
return 'array shift'
|
||||||
|
|
||||||
def _slice(self, start, end):
|
def _slice(self, start, end=None):
|
||||||
return 'array slice'
|
from .utils import to_js
|
||||||
|
|
||||||
|
length = to_uint32(to_js(len(self.value)))
|
||||||
|
start = to_integer(to_js(start))
|
||||||
|
end = length if end is undefined else to_integer(to_js(end))
|
||||||
|
start = min(start, length) if start > 0 else max(length + start, 0)
|
||||||
|
|
||||||
|
return self.value[start:end]
|
||||||
|
|
||||||
def _sort(self, cmp):
|
def _sort(self, cmp):
|
||||||
return 'array sort'
|
return 'array sort'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user