diff --git a/testing/web-platform/tests/dom/observable/tentative/observable-from.any.js b/testing/web-platform/tests/dom/observable/tentative/observable-from.any.js index 42f658102fe5..7af0ff72b900 100644 --- a/testing/web-platform/tests/dom/observable/tentative/observable-from.any.js +++ b/testing/web-platform/tests/dom/observable/tentative/observable-from.any.js @@ -668,20 +668,17 @@ test = > { -let -numTimesSymbolIteratorCalled -= -0 -; -let -numTimesNextCalled +const +results = -0 +[ +] ; const iterable = { +get [ Symbol . @@ -690,19 +687,76 @@ iterator ( ) { -numTimesSymbolIteratorCalled -+ -+ +results +. +push +( +" +[ +Symbol +. +iterator +] +method +GETTER +" +) +; +return +function +( +) +{ +results +. +push +( +" +[ +Symbol +. +iterator +implementation +] +" +) ; return { +get next ( ) { -numTimesNextCalled -+ -+ +results +. +push +( +" +next +( +) +method +GETTER +" +) +; +return +function +( +) +{ +results +. +push +( +" +next +( +) +implementation +" +) ; return { @@ -715,6 +769,10 @@ true } ; } +; +} +} +; } ; } @@ -730,72 +788,21 @@ from iterable ) ; -assert_equals -( -numTimesSymbolIteratorCalled -1 -" -Observable -. -from -( -iterable -) -invokes -the -iterator -method -getter -once -" -) -; -assert_equals -( -numTimesNextCalled -0 -" -Iterator -next +assert_array_equals ( -) -is -not -called -until -subscription +results +[ " -) -; -const -customError -= -new -Error -( -' -iterator -override -error -' -) -; -iterable [ Symbol . iterator ] -= -( +method +GETTER +" +] ) -= -> -{ -throw -customError -; -} ; let thrownError @@ -806,85 +813,52 @@ observable . subscribe ( -{ -error -: -e -= -> -thrownError -= -e -} ) ; -assert_equals +assert_array_equals ( -thrownError -customError +results +[ " -Error -thrown -from -next -( -) -is -passed -to -the -error -( -) -handler +[ +Symbol +. +iterator +] +method +GETTER " -) -; -assert_equals -( -numTimesSymbolIteratorCalled -1 " -Subscription -re -- -invokes +[ +Symbol +. iterator +] method -which -now -is -a -different +GETTER " -+ " -method -that -does -* -not -* -increment -our -assertion -value +[ +Symbol +. +iterator +implementation +] " -) -; -assert_equals +" +next ( -numTimesNextCalled -0 +) +method +GETTER +" " -Iterator next ( ) -is -never -called +implementation " +] ) ; } @@ -916,14 +890,10 @@ test > { let -numTimesSymbolIteratorCalled -= -0 -; -let -numTimesNextCalled +results = -0 +[ +] ; const iterable @@ -934,23 +904,530 @@ Symbol . iterator ] +: +10 +} +; +let +errorThrown += +null +; +try +{ +Observable +. +from ( +iterable ) -{ -numTimesSymbolIteratorCalled -+ -+ ; -return -{ -next +} +catch ( +e ) { -numTimesNextCalled +errorThrown += +e +; +} +assert_true +( +errorThrown +instanceof +TypeError +) +; +assert_equals +( +errorThrown +. +message +" +Failed +to +execute +' +from +' +on +' +Observable +' +: +iterator +must +be +a +" ++ +" +callable +. +" +) +; +} +" +from +( +) +: +[ +Symbol +. +iterator +] +not +callable +" +) +; +test +( +( +) += +> +{ +let +results += +[ +] +; +const +customError += +new +Error +( +" +iterator +override +error +" +) +; +const +iterable += +{ +numTimesCalled +: +0 +get +[ +Symbol +. +iterator +] +( +) +{ +this +. +numTimesCalled + + ; +results +. +push +( +" +[ +Symbol +. +iterator +] +method +GETTER +" +) +; +if +( +this +. +numTimesCalled += += += +1 +) +{ +return +this +. +validIteratorImplementation +; +} +else +{ +return +this +. +errorThrowingIteratorImplementation +; +} +} +validIteratorImplementation +: +function +( +) +{ +results +. +push +( +" +[ +Symbol +. +iterator +implementation +] +" +) +; +return +{ +get +next +( +) +{ +results +. +push +( +" +next +( +) +method +GETTER +" +) +; +return +function +( +) +{ +results +. +push +( +" +next +( +) +implementation +" +) +; +return +{ +value +: +undefined +done +: +true +} +; +} +} +} +; +} +errorThrowingIteratorImplementation +: +function +( +) +{ +results +. +push +( +" +Error +- +throwing +[ +Symbol +. +iterator +] +implementation +" +) +; +throw +customError +; +} +} +; +const +observable += +Observable +. +from +( +iterable +) +; +assert_array_equals +( +results +[ +" +[ +Symbol +. +iterator +] +method +GETTER +" +] +) +; +let +thrownError += +null +; +observable +. +subscribe +( +{ +error +: +e += +> +thrownError += +e +} +) +; +assert_equals +( +thrownError +customError +" +Error +thrown +from +next +( +) +is +passed +to +the +error +( +) +handler +" +) +; +assert_array_equals +( +results +[ +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +Error +- +throwing +[ +Symbol +. +iterator +] +implementation +" +] +) +; +} +" +from +( +) +: +[ +Symbol +. +iterator +] +is +not +cached +" +) +; +test +( +( +) += +> +{ +const +results += +[ +] +; +let +numTimesSymbolIteratorCalled += +0 +; +let +numTimesNextCalled += +0 +; +const +iterable += +{ +get +[ +Symbol +. +iterator +] +( +) +{ +results +. +push +( +" +[ +Symbol +. +iterator +] +method +GETTER +" +) +; +return +this +. +internalIteratorImplementation +; +} +set +[ +Symbol +. +iterator +] +( +func +) +{ +this +. +internalIteratorImplementation += +func +; +} +internalIteratorImplementation +: +function +( +) +{ +results +. +push +( +" +[ +Symbol +. +iterator +] +implementation +" +) +; +return +{ +get +next +( +) +{ +results +. +push +( +" +next +( +) +method +GETTER +" +) +; +return +function +( +) +{ +results +. +push +( +" +next +( +) +implementation +" +) +; return { value @@ -962,6 +1439,8 @@ true } ; } +; +} } ; } @@ -1009,39 +1488,112 @@ obs3 ; assert_equals ( -numTimesSymbolIteratorCalled -3 +obs3 +obs4 +) +; +assert_array_equals +( +results +[ " -Observable +[ +Symbol . -from -( -iterable -) -invokes -the iterator +] method -getter -once +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER " +] ) ; -assert_equals +obs1 +. +subscribe ( -numTimesNextCalled -0 +) +; +assert_array_equals +( +results +[ +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +implementation +" " -Iterator next ( ) -is -not -called -until -subscription +method +GETTER +" +" +next +( +) +implementation " +] ) ; iterable @@ -1056,6 +1608,23 @@ iterator = > { +results +. +push +( +" +Error +- +throwing +[ +Symbol +. +iterator +] +implementation +" +) +; throw new Error @@ -1090,85 +1659,170 @@ errorCount + } ; -obs1 +obs2 . subscribe ( observer ) ; -obs2 +obs3 . subscribe ( observer ) ; -obs3 +obs4 . subscribe ( observer ) ; -obs4 +assert_equals +( +errorCount +3 +" +Error +- +throwing +iterator +implementation +is +called +once +per +" ++ +" +subscription +" +) +; +assert_array_equals +( +results +[ +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol +. +iterator +] +method +GETTER +" +" +[ +Symbol . -subscribe +iterator +] +implementation +" +" +next ( -observer ) -; -assert_equals +method +GETTER +" +" +next ( -errorCount -4 +) +implementation +" +" +[ +Symbol +. +iterator +] +method +GETTER +" " Error - throwing +[ +Symbol +. iterator +] implementation -is -called -once -per " -+ " -subscription +[ +Symbol +. +iterator +] +method +GETTER " -) -; -assert_equals -( -numTimesSymbolIteratorCalled -3 " -Subscription -re +Error - -invokes -the +throwing +[ +Symbol +. +iterator +] +implementation +" +" +[ +Symbol +. iterator +] method -getter -once +GETTER " -) -; -assert_equals -( -numTimesNextCalled -0 " -Iterator -next -( -) -is -never -called +Error +- +throwing +[ +Symbol +. +iterator +] +implementation " +] ) ; } @@ -1912,36 +2566,210 @@ is 0 " ) -; -assert_equals +; +assert_equals +( +errorReported +. +colno +0 +" +Error +lineno +is +0 +" +) +; +assert_equals +( +errorReported +. +error +" +custom +reason +" +" +Error +object +is +equivalent +" +) +; +} +" +from +( +) +: +Rejections +not +handled +by +subscription +are +reported +to +the +" ++ +" +global +and +still +not +sent +as +an +unhandledrejection +event +" +) +; +test +( +( +) += +> +{ +const +results += +[ +] +; +const +observable += +new +Observable +( +subscriber += +> +{ +subscriber +. +next +( +' +from +Observable +' +) +; +subscriber +. +complete +( +) +; +} +) +; +observable +[ +Symbol +. +iterator +] += +( +) += +> +{ +results +. +push +( +' +Symbol +. +iterator +( +) +called +' +) +; +return +{ +next +( +) +{ +return +{ +value +: +' +from +iterator +' +done +: +true +} +; +} +} +; +} +; +Observable +. +from +( +observable +) +. +subscribe +( +{ +next +: +v += +> +results +. +push +( +v +) +complete +: ( -errorReported +) += +> +results . -colno -0 +push +( " -Error -lineno -is -0 +complete " ) +} +) ; -assert_equals +assert_array_equals ( -errorReported -. -error +results +[ " -custom -reason +from +Observable " " -Error -object -is -equivalent +complete " +] ) ; } @@ -1950,27 +2778,21 @@ from ( ) : -Rejections -not -handled -by -subscription -are -reported -to -the +Observable +that +implements +iterator +protocol +gets +converted " + " -global -and -still -not -sent as an -unhandledrejection -event +Observable +not +iterator " ) ; @@ -1988,35 +2810,27 @@ results ] ; const -observable +promise = new -Observable +Promise ( -subscriber +resolve = > { -subscriber -. -next +resolve ( ' from -Observable +Promise ' ) ; -subscriber -. -complete -( -) -; } ) ; -observable +promise [ Symbol . @@ -2028,19 +2842,10 @@ iterator = > { -results -. -push -( -' -Symbol -. -iterator -( -) -called -' -) +let +done += +false ; return { @@ -2048,6 +2853,16 @@ next ( ) { +if +( +! +done +) +{ +done += +true +; return { value @@ -2058,11 +2873,25 @@ iterator ' done : +false +} +; +} +else +{ +return +{ +value +: +undefined +done +: true } ; } } +} ; } ; @@ -2070,7 +2899,7 @@ Observable . from ( -observable +promise ) . subscribe @@ -2104,18 +2933,140 @@ complete } ) ; -assert_array_equals +assert_array_equals +( +results +[ +" +from +iterator +" +" +complete +" +] +) +; +} +" +from +( +) +: +Promise +that +implements +iterator +protocol +gets +converted +as +" ++ +" +an +iterable +not +Promise +" +) +; +promise_test +( +async +( +) += +> +{ +const +promise += +new +Promise +( +resolve += +> +resolve +( +' +from +Promise +' +) +) +; +assert_equals +( +promise +[ +Symbol +. +iterator +] +undefined +) +; +promise +[ +Symbol +. +iterator +] += +null +; +assert_equals +( +promise +[ +Symbol +. +iterator +] +null +) +; +const +value += +await +new +Promise +( +resolve += +> +{ +Observable +. +from +( +promise +) +. +subscribe +( +value += +> +resolve +( +value +) +) +; +} +) +; +assert_equals ( -results -[ -" +value +' from -Observable -" -" -complete -" -] +Promise +' ) ; } @@ -2124,21 +3075,18 @@ from ( ) : -Observable -that -implements +Promise +whose +[ +Symbol +. iterator -protocol -gets -converted -" -+ -" +] +returns +null +converts as -an -Observable -not -iterator +Promise " ) ; @@ -2150,170 +3098,203 @@ test > { const -results -= -[ -] -; -const -promise +error = new -Promise -( -resolve -= -> -{ -resolve +Error ( ' +thrown from -Promise +iterator +getter ' ) ; -} -) -; -promise +const +obj += +{ +get [ Symbol . iterator ] -= ( ) -= -> { -let -done -= -false +throw +error ; -return -{ -next -( -) +} +} +try { -if +Observable +. +from ( -! -done +obj ) -{ -done -= -true ; -return -{ -value -: -' +assert_unreached +( +" from -iterator -' -done -: -false -} +( +) +conversion +throws +" +) ; } -else -{ -return +catch +( +e +) { -value -: -undefined -done -: -true -} +assert_equals +( +e +error +) ; } } -} -; -} -; -Observable -. +" from ( -promise ) -. -subscribe -( -{ -next : -v -= -> -results -. -push -( -v +Rethrows +the +error +when +Converting +an +object +whose +iterator +" ++ +" +method +* +getter +* +throws +an +error +" ) -complete -: +; +test +( ( ) = > -results +{ +const +obj += +{ +} +; +obj +[ +Symbol . -push +iterator +] += +10 +; +try +{ +Observable +. +from +( +obj +) +; +assert_unreached ( " -complete +from +( +) +conversion +throws " ) +; } +catch +( +e +) +{ +assert_true +( +e +instanceof +TypeError ) ; -assert_array_equals +assert_equals ( -results -[ +e +. +message " +Failed +to +execute +' from +' +on +' +Observable +' +: iterator +must +be +a +callable +. " -" -complete -" -] ) ; } +} " from ( ) : -Promise -that -implements +Throws +' +callable +' +error +when iterator -protocol -gets -converted -as +property +is +a " + " -an -iterable -not -Promise +non +- +callable +primitive " ) ;