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

Side by Side Diff: Source/bindings/v8/custom/V8ArrayBufferCustom.cpp

Issue 15877002: move constructors to new style callbacks (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 V8ArrayBufferDeallocationObserver* V8ArrayBufferDeallocationObserver::instance() 43 V8ArrayBufferDeallocationObserver* V8ArrayBufferDeallocationObserver::instance()
44 { 44 {
45 DEFINE_STATIC_LOCAL(V8ArrayBufferDeallocationObserver, deallocationObserver, ()); 45 DEFINE_STATIC_LOCAL(V8ArrayBufferDeallocationObserver, deallocationObserver, ());
46 return &deallocationObserver; 46 return &deallocationObserver;
47 } 47 }
48 48
49 49
50 v8::Handle<v8::Value> V8ArrayBuffer::constructorCustom(const v8::Arguments& args ) 50 void V8ArrayBuffer::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
51 { 51 {
52 // If we return a previously constructed ArrayBuffer, 52 // If we return a previously constructed ArrayBuffer,
53 // e.g. from the call to ArrayBufferView.buffer, this code is called 53 // e.g. from the call to ArrayBufferView.buffer, this code is called
54 // with a zero-length argument list. The V8DOMWrapper will then 54 // with a zero-length argument list. The V8DOMWrapper will then
55 // set the internal pointer in the newly-created object. 55 // set the internal pointer in the newly-created object.
56 // Unfortunately it doesn't look like it's possible to distinguish 56 // Unfortunately it doesn't look like it's possible to distinguish
57 // between this case and that where the user calls "new 57 // between this case and that where the user calls "new
58 // ArrayBuffer()" from JavaScript. To guard against problems, 58 // ArrayBuffer()" from JavaScript. To guard against problems,
59 // we always create at least a zero-length ArrayBuffer, even 59 // we always create at least a zero-length ArrayBuffer, even
60 // if it is immediately overwritten by the V8DOMWrapper. 60 // if it is immediately overwritten by the V8DOMWrapper.
61 61
62 // Supported constructors: 62 // Supported constructors:
63 // ArrayBuffer(n) where n is an integer: 63 // ArrayBuffer(n) where n is an integer:
64 // -- create an empty buffer of n bytes 64 // -- create an empty buffer of n bytes
65 65
66 int argLength = args.Length(); 66 int argLength = args.Length();
67 int length = 0; 67 int length = 0;
68 if (argLength > 0) 68 if (argLength > 0)
69 length = toInt32(args[0]); // NaN/+inf/-inf returns 0, this is intended by WebIDL 69 length = toInt32(args[0]); // NaN/+inf/-inf returns 0, this is intended by WebIDL
70 RefPtr<ArrayBuffer> buffer; 70 RefPtr<ArrayBuffer> buffer;
71 if (length >= 0) 71 if (length >= 0)
72 buffer = ArrayBuffer::create(static_cast<unsigned>(length), 1); 72 buffer = ArrayBuffer::create(static_cast<unsigned>(length), 1);
73 if (!buffer.get()) 73 if (!buffer.get()) {
74 return throwError(v8RangeError, "ArrayBuffer size is not a small enough positive integer.", args.GetIsolate()); 74 throwError(v8RangeError, "ArrayBuffer size is not a small enough positiv e integer.", args.GetIsolate());
75 return;
76 }
75 buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance( )); 77 buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance( ));
76 v8::V8::AdjustAmountOfExternalAllocatedMemory(buffer->byteLength()); 78 v8::V8::AdjustAmountOfExternalAllocatedMemory(buffer->byteLength());
77 // Transform the holder into a wrapper object for the array. 79 // Transform the holder into a wrapper object for the array.
78 v8::Handle<v8::Object> wrapper = args.Holder(); 80 v8::Handle<v8::Object> wrapper = args.Holder();
79 V8DOMWrapper::associateObjectWithWrapper(buffer.release(), &info, wrapper, a rgs.GetIsolate(), WrapperConfiguration::Dependent); 81 V8DOMWrapper::associateObjectWithWrapper(buffer.release(), &info, wrapper, a rgs.GetIsolate(), WrapperConfiguration::Dependent);
80 return wrapper; 82 args.GetReturnValue().Set(wrapper);
81 } 83 }
82 84
83 } // namespace WebCore 85 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698