Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18563] HAL: const JSObject cannot be used in concurrency::task().then

GitHub Issuen/a
TypeImprovement
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2015-02-13T01:47:35.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsWindows
Labelsn/a
ReporterGary Mathews
AssigneeIngo Muschenetz
Created2015-02-12T23:41:23.000+0000
Updated2017-03-24T17:09:38.000+0000

Description

JSObject cannot be used in a concurrency::task().then callback without statically casting it back to a non-const. *Examples*
JSValue GeolocationModule::forwardGeocoder(const std::string& address, JSObject callback) TITANIUM_NOEXCEPT
{
	...

	concurrency::create_task(httpClient->GetAsync(requestUri)).then([this, address, callback](HttpResponseMessage^ response) {
		
		...

		TITANIUM_ASSERT(callback.IsFunction());

		// I would need to statically cast callback as a non-const
		// JSObject to be able to use it
		callback({forwardGeocodeResponse}, get_context().get_global_object());
	});

    return get_context().CreateUndefined();
}

Comments

  1. Kota Iguchi 2015-02-13

    You can use "&" to pass it as reference to lambda like "&callback" in this case.
           concurrency::create_task(httpClient->GetAsync(requestUri)).then([this, address, &callback](HttpResponseMessage^ response) {
               TITANIUM_ASSERT(callback.IsFunction());
               callback({forwardGeocodeResponse}, get_context().get_global_object());
           });
       
  2. Lee Morris 2017-03-24

    Closing ticket as invalid.

JSON Source