Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: mojo/edk/js/core.cc

Issue 2358513002: [mojo] Initialize MojoCreateSharedBufferOptions struct size. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/js/core.h" 5 #include "mojo/edk/js/core.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return gin::Converter<gin::Handle<mojo::edk::js::HandleWrapper>>::FromV8( 288 return gin::Converter<gin::Handle<mojo::edk::js::HandleWrapper>>::FromV8(
289 args->isolate(), val, &ignore_handle); 289 args->isolate(), val, &ignore_handle);
290 } 290 }
291 291
292 gin::Dictionary CreateSharedBuffer(const gin::Arguments& args, 292 gin::Dictionary CreateSharedBuffer(const gin::Arguments& args,
293 uint64_t num_bytes, 293 uint64_t num_bytes,
294 MojoCreateSharedBufferOptionsFlags flags) { 294 MojoCreateSharedBufferOptionsFlags flags) {
295 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 295 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
296 MojoHandle handle = MOJO_HANDLE_INVALID; 296 MojoHandle handle = MOJO_HANDLE_INVALID;
297 MojoCreateSharedBufferOptions options; 297 MojoCreateSharedBufferOptions options;
298 // The |flags| is mandatory parameter for CreateSharedBuffer, and it will
299 // be always initialized in MojoCreateSharedBufferOptions struct. For
300 // forward compatibility, set struct_size to be 8 bytes (struct_size + flags),
301 // so that validator will only check the field that is set.
302 options.struct_size = 8;
298 options.flags = flags; 303 options.flags = flags;
299 MojoResult result = MojoCreateSharedBuffer(&options, num_bytes, &handle); 304 MojoResult result = MojoCreateSharedBuffer(&options, num_bytes, &handle);
300 if (result != MOJO_RESULT_OK) { 305 if (result != MOJO_RESULT_OK) {
301 dictionary.Set("result", result); 306 dictionary.Set("result", result);
302 return dictionary; 307 return dictionary;
303 } 308 }
304 309
305 dictionary.Set("result", result); 310 dictionary.Set("result", result);
306 dictionary.Set("handle", mojo::Handle(handle)); 311 dictionary.Set("handle", mojo::Handle(handle));
307 312
308 return dictionary; 313 return dictionary;
309 } 314 }
310 315
311 gin::Dictionary DuplicateBufferHandle( 316 gin::Dictionary DuplicateBufferHandle(
312 const gin::Arguments& args, 317 const gin::Arguments& args,
313 mojo::Handle handle, 318 mojo::Handle handle,
314 MojoDuplicateBufferHandleOptionsFlags flags) { 319 MojoDuplicateBufferHandleOptionsFlags flags) {
315 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 320 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
316 MojoHandle duped = MOJO_HANDLE_INVALID; 321 MojoHandle duped = MOJO_HANDLE_INVALID;
317 MojoDuplicateBufferHandleOptions options; 322 MojoDuplicateBufferHandleOptions options;
318 // The |flags| is mandatory parameter for DuplicateBufferHandle, and it will 323 // The |flags| is mandatory parameter for DuplicateBufferHandle, and it will
319 // be always initialized in MojoDuplicateBufferHandleOptions struct. For now, 324 // be always initialized in MojoDuplicateBufferHandleOptions struct. For
320 // since the struct has only one options field (flags), set struct_size to be 325 // forward compatibility, set struct_size to be 8 bytes (struct_size + flags),
321 // equal to the size of MojoDuplicateBufferHandleOptions. 326 // so that validator will only check the field that is set.
322 options.struct_size = 327 options.struct_size = 8;
323 static_cast<uint32_t>(sizeof(MojoDuplicateBufferHandleOptions));
324 options.flags = flags; 328 options.flags = flags;
325 MojoResult result = 329 MojoResult result =
326 MojoDuplicateBufferHandle(handle.value(), &options, &duped); 330 MojoDuplicateBufferHandle(handle.value(), &options, &duped);
327 if (result != MOJO_RESULT_OK) { 331 if (result != MOJO_RESULT_OK) {
328 dictionary.Set("result", result); 332 dictionary.Set("result", result);
329 return dictionary; 333 return dictionary;
330 } 334 }
331 335
332 dictionary.Set("result", result); 336 dictionary.Set("result", result);
333 dictionary.Set("handle", mojo::Handle(duped)); 337 dictionary.Set("handle", mojo::Handle(duped));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 468
465 data->SetObjectTemplate(&g_wrapper_info, templ); 469 data->SetObjectTemplate(&g_wrapper_info, templ);
466 } 470 }
467 471
468 return templ->NewInstance(); 472 return templ->NewInstance();
469 } 473 }
470 474
471 } // namespace js 475 } // namespace js
472 } // namespace edk 476 } // namespace edk
473 } // namespace mojo 477 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698