diff --git a/arangod/Actions/RestActionHandler.cpp b/arangod/Actions/RestActionHandler.cpp index 7a6a622d5f..3640573e98 100644 --- a/arangod/Actions/RestActionHandler.cpp +++ b/arangod/Actions/RestActionHandler.cpp @@ -49,15 +49,15 @@ using namespace triagens::arango; RestActionHandler::RestActionHandler (HttpRequest* request, action_options_t* data) : RestVocbaseBaseHandler(request), - _action(0), + _action(nullptr), _queue(), _dataLock(), - _data(0) { + _data(nullptr) { _action = TRI_LookupActionVocBase(request); // use the queue from options if an action is known - if (_action != 0) { + if (_action != nullptr) { _queue = data->_queue; } @@ -76,7 +76,7 @@ RestActionHandler::RestActionHandler (HttpRequest* request, //////////////////////////////////////////////////////////////////////////////// bool RestActionHandler::isDirect () { - return _action == 0; + return _action == nullptr; } //////////////////////////////////////////////////////////////////////////////// @@ -102,7 +102,7 @@ HttpHandler::status_t RestActionHandler::execute () { } // need an action - if (_action == 0) { + if (_action == nullptr) { generateNotImplemented(_request->requestPath()); } @@ -185,7 +185,7 @@ TRI_action_result_t RestActionHandler::executeAction () { result.isValid = true; generateNotImplemented(_action->_url); } - + return result; } diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index f1e128f721..ce132ee9ff 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -46,7 +46,6 @@ #include "HttpServer/ApplicationEndpointServer.h" #include "V8/v8-conv.h" -#include "V8/v8-execution.h" #include "V8/v8-utils.h" #include "Wal/LogfileManager.h" @@ -1067,22 +1066,23 @@ static v8::Handle JS_ExecuteAqlJson (v8::Arguments const& argv) { return scope.Close(result); } - TRI_json_t* extra = nullptr; - if (queryResult.warnings != nullptr && queryResult.stats != nullptr) { - extra = TRI_MergeJson(TRI_UNKNOWN_MEM_ZONE, queryResult.stats, queryResult.warnings, true); - - if (extra == nullptr) { - TRI_V8_EXCEPTION_MEMORY(scope); - } + TRI_json_t* extra = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE); + if (extra == nullptr) { + TRI_V8_EXCEPTION_MEMORY(scope); } - else if (queryResult.warnings != nullptr) { - extra = queryResult.warnings; + + if (queryResult.warnings != nullptr) { + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, extra, "warnings", queryResult.warnings); queryResult.warnings = nullptr; } - else if (queryResult.stats != nullptr) { - extra = queryResult.stats; + if (queryResult.stats != nullptr) { + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, extra, "stats", queryResult.stats); queryResult.stats = nullptr; } + if (queryResult.profile != nullptr) { + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, extra, "profile", queryResult.profile); + queryResult.profile = nullptr; + } TRI_general_cursor_result_t* cursorResult = TRI_CreateResultGeneralCursor(queryResult.json); @@ -1202,20 +1202,13 @@ static v8::Handle JS_ExecuteAql (v8::Arguments const& argv) { auto queryResult = query.execute(static_cast(v8g->_queryRegistry)); -/* TODO: check if we need this here! - if (tryCatch.HasCaught()) { - if (tryCatch.CanContinue()) { - return scope.Close(v8::ThrowException(tryCatch.Exception())); - } - else { + if (queryResult.code != TRI_ERROR_NO_ERROR) { + if (queryResult.code == TRI_ERROR_REQUEST_CANCELED) { TRI_v8_global_t* v8g = static_cast(v8::Isolate::GetCurrent()->GetData()); - v8g->_canceled = true; return scope.Close(TRI_CreateErrorObject(__FILE__, __LINE__, TRI_ERROR_REQUEST_CANCELED)); } - } -*/ - if (queryResult.code != TRI_ERROR_NO_ERROR) { + TRI_V8_EXCEPTION_FULL(scope, queryResult.code, queryResult.details); } @@ -1239,24 +1232,25 @@ static v8::Handle JS_ExecuteAql (v8::Arguments const& argv) { } return scope.Close(result); } - - TRI_json_t* extra = nullptr; - if (queryResult.warnings != nullptr && queryResult.stats != nullptr) { - extra = TRI_MergeJson(TRI_UNKNOWN_MEM_ZONE, queryResult.stats, queryResult.warnings, true); - - if (extra == nullptr) { - TRI_V8_EXCEPTION_MEMORY(scope); - } + + TRI_json_t* extra = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE); + if (extra == nullptr) { + TRI_V8_EXCEPTION_MEMORY(scope); } - else if (queryResult.warnings != nullptr) { - extra = queryResult.warnings; + + if (queryResult.warnings != nullptr) { + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, extra, "warnings", queryResult.warnings); queryResult.warnings = nullptr; } - else if (queryResult.stats != nullptr) { - extra = queryResult.stats; + if (queryResult.stats != nullptr) { + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, extra, "stats", queryResult.stats); queryResult.stats = nullptr; } - + if (queryResult.profile != nullptr) { + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, extra, "profile", queryResult.profile); + queryResult.profile = nullptr; + } + TRI_general_cursor_result_t* cursorResult = TRI_CreateResultGeneralCursor(queryResult.json); if (cursorResult == nullptr) { diff --git a/js/actions/api-cursor.js b/js/actions/api-cursor.js index 79acfb3d0f..0dac06291b 100644 --- a/js/actions/api-cursor.js +++ b/js/actions/api-cursor.js @@ -245,8 +245,8 @@ var internal = require("internal"); /// var response = logCurlRequest('POST', url, JSON.stringify(body)); /// /// assert(response.code === 201); -/// assert(JSON.parse(response.body).extra.operations.executed === 2); -/// assert(JSON.parse(response.body).extra.operations.ignored === 0); +/// assert(JSON.parse(response.body).extra.stats.writesExecuted === 2); +/// assert(JSON.parse(response.body).extra.stats.writesIgnored === 0); /// /// logJsonResponse(response); /// @END_EXAMPLE_ARANGOSH_RUN @@ -268,8 +268,8 @@ var internal = require("internal"); /// var response = logCurlRequest('POST', url, JSON.stringify(body)); /// /// assert(response.code === 201); -/// assert(JSON.parse(response.body).extra.operations.executed === 0); -/// assert(JSON.parse(response.body).extra.operations.ignored === 1); +/// assert(JSON.parse(response.body).extra.stats.writesExecuted === 0); +/// assert(JSON.parse(response.body).extra.stats.writesIgnored === 1); /// /// logJsonResponse(response); /// @END_EXAMPLE_ARANGOSH_RUN diff --git a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/simple-query-common.js b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/simple-query-common.js index ad4728a80b..5f48c4f698 100644 --- a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/simple-query-common.js +++ b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/simple-query-common.js @@ -50,12 +50,21 @@ var SimpleQueryWithin; /// @brief array query //////////////////////////////////////////////////////////////////////////////// -function GeneralArrayCursor (documents, skip, limit, extra) { +function GeneralArrayCursor (documents, skip, limit, data) { this._documents = documents; this._countTotal = documents.length; this._skip = skip; this._limit = limit; - this._extra = extra; + this._extra = { }; + + var self = this; + if (data !== null && data !== undefined && typeof data === 'object') { + [ 'stats', 'warnings', 'profile' ].forEach(function(d) { + if (data.hasOwnProperty(d)) { + self._extra[d] = data[d]; + } + }); + } this.execute(); } diff --git a/js/common/modules/org/arangodb/simple-query-common.js b/js/common/modules/org/arangodb/simple-query-common.js index 360ae44fef..14a8a6c97a 100644 --- a/js/common/modules/org/arangodb/simple-query-common.js +++ b/js/common/modules/org/arangodb/simple-query-common.js @@ -49,12 +49,21 @@ var SimpleQueryWithin; /// @brief array query //////////////////////////////////////////////////////////////////////////////// -function GeneralArrayCursor (documents, skip, limit, extra) { +function GeneralArrayCursor (documents, skip, limit, data) { this._documents = documents; this._countTotal = documents.length; this._skip = skip; this._limit = limit; - this._extra = extra; + this._extra = { }; + + var self = this; + if (data !== null && data !== undefined && typeof data === 'object') { + [ 'stats', 'warnings', 'profile' ].forEach(function(d) { + if (data.hasOwnProperty(d)) { + self._extra[d] = data[d]; + } + }); + } this.execute(); } diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index ec596ce4e4..9382a5a799 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -1719,11 +1719,11 @@ function resultCursor (req, res, cursor, code, options) { cursor.dispose(); } } - else if (cursor.hasOwnProperty('docs')) { + else if (cursor.hasOwnProperty('json')) { // cursor is a regular JS object (performance optimisation) hasCount = ((options && options.countRequested) ? true : false); - count = cursor.docs.length; - rows = cursor.docs; + count = cursor.json.length; + rows = cursor.json; extra = cursor.extra; hasNext = false; cursorId = null; diff --git a/js/server/modules/org/arangodb/arango-statement.js b/js/server/modules/org/arangodb/arango-statement.js index ea23fc9a7e..11beed0feb 100644 --- a/js/server/modules/org/arangodb/arango-statement.js +++ b/js/server/modules/org/arangodb/arango-statement.js @@ -75,7 +75,7 @@ ArangoStatement.prototype.execute = function () { } var result = AQL_EXECUTE(this._query, this._bindVars, options); - return new GeneralArrayCursor(result.json, 0, null, result.extra); + return new GeneralArrayCursor(result.json, 0, null, result); }; // ----------------------------------------------------------------------------- diff --git a/js/server/tests/aql-optimizer-rule-use-index-for-sort.js b/js/server/tests/aql-optimizer-rule-use-index-for-sort.js index 8b8dba8d6f..8315501123 100644 --- a/js/server/tests/aql-optimizer-rule-use-index-for-sort.js +++ b/js/server/tests/aql-optimizer-rule-use-index-for-sort.js @@ -1,5 +1,5 @@ /*jshint strict: false, maxlen: 500 */ -/*global require, assertEqual, assertTrue, AQL_EXPLAIN, AQL_EXECUTE */ +/*global require, assertEqual, assertTrue, assertNotEqual, AQL_EXPLAIN, AQL_EXECUTE */ //////////////////////////////////////////////////////////////////////////////// /// @brief tests for optimizer rules diff --git a/js/server/tests/shell-transactions-noncluster.js b/js/server/tests/shell-transactions-noncluster.js index 1caac1ab31..d0e40d1592 100644 --- a/js/server/tests/shell-transactions-noncluster.js +++ b/js/server/tests/shell-transactions-noncluster.js @@ -752,8 +752,8 @@ function transactionCollectionsSuite () { write: [ cn1 ] }, action : function () { - var ops = db._query("FOR i IN @@cn1 REMOVE i._key IN @@cn1", { "@cn1" : cn1 }).getExtra().operations; - assertEqual(10, ops.executed); + var ops = db._query("FOR i IN @@cn1 REMOVE i._key IN @@cn1", { "@cn1" : cn1 }).getExtra().stats; + assertEqual(10, ops.writesExecuted); assertEqual(0, c1.count()); return true; } @@ -780,8 +780,8 @@ function transactionCollectionsSuite () { write: [ cn2 ] }, action : function () { - var ops = db._query("FOR i IN @@cn1 REMOVE i._key IN @@cn2", { "@cn1" : cn1, "@cn2" : cn2 }).getExtra().operations; - assertEqual(10, ops.executed); + var ops = db._query("FOR i IN @@cn1 REMOVE i._key IN @@cn2", { "@cn1" : cn1, "@cn2" : cn2 }).getExtra().stats; + assertEqual(10, ops.writesExecuted); return true; } }; @@ -844,12 +844,12 @@ function transactionCollectionsSuite () { }, action : function () { var ops; - ops = db._query("FOR i IN @@cn1 REMOVE i._key IN @@cn1", { "@cn1" : cn1 }).getExtra().operations; - assertEqual(10, ops.executed); + ops = db._query("FOR i IN @@cn1 REMOVE i._key IN @@cn1", { "@cn1" : cn1 }).getExtra().stats; + assertEqual(10, ops.writesExecuted); assertEqual(0, c1.count()); - ops = db._query("FOR i IN @@cn2 REMOVE i._key IN @@cn2", { "@cn2" : cn2 }).getExtra().operations; - assertEqual(10, ops.executed); + ops = db._query("FOR i IN @@cn2 REMOVE i._key IN @@cn2", { "@cn2" : cn2 }).getExtra().stats; + assertEqual(10, ops.writesExecuted); assertEqual(0, c2.count()); return true; } diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 35ed2ef19b..a8c8b7d9b3 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -198,7 +198,6 @@ add_library( V8/V8StringConverter.cpp V8/v8-buffer.cpp V8/v8-conv.cpp - V8/v8-execution.cpp V8/v8-globals.cpp V8/v8-json.cpp V8/v8-shell.cpp diff --git a/lib/Makefile.files b/lib/Makefile.files index 31a668c139..58b33e2444 100644 --- a/lib/Makefile.files +++ b/lib/Makefile.files @@ -181,7 +181,6 @@ lib_libarango_v8_a_SOURCES = \ lib/V8/V8StringConverter.cpp \ lib/V8/v8-buffer.cpp \ lib/V8/v8-conv.cpp \ - lib/V8/v8-execution.cpp \ lib/V8/v8-globals.cpp \ lib/V8/v8-json.cpp \ lib/V8/v8-shell.cpp \ diff --git a/lib/V8/v8-execution.cpp b/lib/V8/v8-execution.cpp deleted file mode 100644 index 02c0bc6a78..0000000000 --- a/lib/V8/v8-execution.cpp +++ /dev/null @@ -1,163 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief V8 utility functions -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2014 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany -/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#include "v8-execution.h" - -#include "V8/v8-conv.h" - -using namespace std; - -// ----------------------------------------------------------------------------- -// --SECTION-- EXECUTION CONTEXT -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- public types -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a new execution context -//////////////////////////////////////////////////////////////////////////////// - -TRI_js_exec_context_t* TRI_CreateExecutionContext (char const* script, - size_t length) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - TRI_js_exec_context_t* ctx = new TRI_js_exec_context_t; - ctx->_error = TRI_ERROR_NO_ERROR; - - // execute script inside the context - v8::Handle compiled = v8::Script::Compile(v8::String::New(script, (int) length), - v8::String::New("--script--")); - - // compilation failed, return - if (compiled.IsEmpty()) { - ctx->_error = TRI_ERROR_INTERNAL; - return ctx; - } - - // compute the function - v8::TryCatch tryCatch; - v8::Handle val = compiled->Run(); - - if (tryCatch.HasCaught()) { - if (tryCatch.CanContinue()) { - ctx->_error = TRI_ERROR_INTERNAL; - } - else { - TRI_v8_global_t* v8g = static_cast(v8::Isolate::GetCurrent()->GetData()); - - v8g->_canceled = true; - ctx->_error = TRI_ERROR_REQUEST_CANCELED; - } - return ctx; - } - - if (val.IsEmpty()) { - ctx->_error = TRI_ERROR_INTERNAL; - return ctx; - } - - ctx->_func = v8::Persistent::New(isolate, v8::Handle::Cast(val)); - ctx->_arguments = v8::Persistent::New(isolate, v8::Object::New()); - ctx->_isolate = isolate; - ctx->_error = TRI_ERROR_NO_ERROR; - - // return the handle - return ctx; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees an new execution context -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeExecutionContext (TRI_js_exec_context_t* ctx) { - if (ctx->_error == TRI_ERROR_NO_ERROR) { - ctx->_func.Dispose(ctx->_isolate); - ctx->_func.Clear(); - - ctx->_arguments.Dispose(ctx->_isolate); - ctx->_arguments.Clear(); - } - - delete ctx; -} - -// ----------------------------------------------------------------------------- -// --SECTION-- public functions -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a result context -//////////////////////////////////////////////////////////////////////////////// - -TRI_json_t* TRI_ExecuteResultContext (TRI_js_exec_context_t* ctx) { - TRI_ASSERT(ctx->_error == TRI_ERROR_NO_ERROR); - - // convert back into a handle - v8::Persistent func = ctx->_func; - - v8::TryCatch tryCatch; - - // and execute the function - v8::Handle args[] = { ctx->_arguments }; - v8::Handle result = func->Call(func, 1, args); - - if (tryCatch.HasCaught()) { - if (tryCatch.CanContinue()) { - ctx->_error = TRI_ERROR_INTERNAL; - } - else { - TRI_v8_global_t* v8g = static_cast(v8::Isolate::GetCurrent()->GetData()); - - v8g->_canceled = true; - ctx->_error = TRI_ERROR_REQUEST_CANCELED; - } - return NULL; - } - - if (result.IsEmpty()) { - ctx->_error = TRI_ERROR_INTERNAL; - return NULL; - } - - return TRI_ObjectToJson(result); -} - -// ----------------------------------------------------------------------------- -// --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- - -// Local Variables: -// mode: outline-minor -// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" -// End: diff --git a/lib/V8/v8-execution.h b/lib/V8/v8-execution.h deleted file mode 100644 index d643bf2e96..0000000000 --- a/lib/V8/v8-execution.h +++ /dev/null @@ -1,94 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief V8 execution context -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2014 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany -/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ARANGODB_V8_V8__EXECUTION_H -#define ARANGODB_V8_V8__EXECUTION_H 1 - -#include "Basics/Common.h" - -#include - -// ----------------------------------------------------------------------------- -// --SECTION-- forward declarations -// ----------------------------------------------------------------------------- - -struct TRI_json_t; - -// ----------------------------------------------------------------------------- -// --SECTION-- public types -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief execution context -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_js_exec_context_s { - v8::Isolate* _isolate; - v8::Persistent _func; - v8::Persistent _arguments; - int _error; -} -TRI_js_exec_context_t; - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a new execution context -//////////////////////////////////////////////////////////////////////////////// - -TRI_js_exec_context_t* TRI_CreateExecutionContext (const char*, size_t); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees an new execution context -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeExecutionContext (TRI_js_exec_context_t*); - -// ----------------------------------------------------------------------------- -// --SECTION-- public functions -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a result context -//////////////////////////////////////////////////////////////////////////////// - -struct TRI_json_t* TRI_ExecuteResultContext (TRI_js_exec_context_t* context); - -#endif - -// ----------------------------------------------------------------------------- -// --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- - -// Local Variables: -// mode: outline-minor -// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" -// End: